Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible_env_vars are not set before version check #157

Open
kernel-sanders opened this issue May 17, 2023 · 0 comments
Open

ansible_env_vars are not set before version check #157

kernel-sanders opened this issue May 17, 2023 · 0 comments
Labels

Comments

@kernel-sanders
Copy link

Overview of the Issue

When using the ansible provisioner on a system with home directories that are read only, it will fail with Error running "ansible-playbook --version": exit status 5

Reproduction Steps

Create a packer file with an ansible provisioner and custom env vars. We will use a test script as the command to see the full output.

...
  provisioner "ansible" {
    command = "/tmp/test.sh"
    user = "${var.ssh_username}"
    use_proxy = false
    extra_arguments = ["-vvv"]
    ansible_env_vars = ["ANSIBLE_HOME=${var.ansible_home}", "TEST_ENV_VAR=JUST_FOR_TESTING"]
    playbook_file   = "playbook.yml"
  }
...

/tmp/test.sh contains

#!/bin/bash
env > /tmp/env.log
strace /usr/local/bin/ansible-playbook "$@" >> /tmp/ansible-debug.log 2>/tmp/strace.log

Run the packer file and view the env.log and strace.log files. The env.log will show that none of the custom ansible_env_vars are set, and strace will show an error writing to the default home directory (assuming your home directory is read-only)

mkdir("/home/username/.ansible/tmp/ansible-local-38561yu5y65d3", 0700) = -1 EROFS (Read-only file system)
write(2, "ERROR: Unhandled exception when "..., 240ERROR: Unhandled exception when retrieving DEFAULT_LOCAL_TMP:
[Errno 30] Read-only file system: '/home/username/.ansible/tmp/ansible-local-38561yu5y65d3'. [Errno 30] Read-only file system: '/home/username/.ansible/tmp/ansible-local-38561yu5y65d3') = 240

Adding skip_version_check = true to the ansible provisioner prevents this error, as the env vars are set correctly before the actual ansible playbook is run.

Packer version

Packer v1.8.5

Operating system and Environment details

Debian 11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant