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 fails to run inside the hashicorp/packer docker image #200

Open
thunderpants73 opened this issue Oct 4, 2024 · 4 comments
Open
Labels

Comments

@thunderpants73
Copy link

When using the ansible provisioner with the hashicorp/packer docker image ansible-playbook fails to run with the following error:

13:08:42  Error: Failed preparing provisioner-block "ansible" ""
13:08:42  
13:08:42    on template.pkr.hcl line 46:
13:08:42    (source code not available)
13:08:42  
13:08:42  1 error(s) occurred:
13:08:42  
13:08:42  * Error running "ansible-playbook --version": exit status 5

I've tried this with multiple versions of the docker image, all error with the same thing. My provisioner block is very simple:

  provisioner "ansible" {
    playbook_file   = "playbooks/post-config.yaml"
    user = "root"
  }

Has anyone seen this issue before?

@lbajolet-hashicorp
Copy link
Contributor

Hi @thunderpants73,

That doesn't surprise me, the full image embeds Packer and the Ansible plugin, but not ansible itself. This is something we should probably investigate/fix, but I would suggest running commands to install those before invoking a build on your template in the meantime.

@thunderpants73
Copy link
Author

@lbajolet-hashicorp - We did try that. We added the ansible packages to the Docker image. The error above is what we get with those packages added.

RUN apk add ansible jq openssh bash curl py3-boto3 sudo

@lbajolet-hashicorp
Copy link
Contributor

That is strange; I've tried to run this in a local hashicorp/packer container, only running apk install ansible && ansible-playbook --version, which succeeds as expected; it seems unlikely, but if you try to invoke ansible-playbook --version manually on your container, could you report what happens?

@thunderpants73
Copy link
Author

Yep, we did that as well. This is the output from our pipeline.

12:39:24  #5 [2/2] RUN apk add ansible jq openssh bash curl py3-boto3 sudo && ansible-playbook --version

12:39:32  #5 7.574 OK: 625 MiB in 132 packages
12:39:32  #5 8.090 ansible-playbook [core 2.17.0]
12:39:32  #5 8.090   config file = None
12:39:32  #5 8.090   configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
12:39:32  #5 8.090   ansible python module location = /usr/lib/python3.12/site-packages/ansible
12:39:32  #5 8.090   ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
12:39:32  #5 8.090   executable location = /usr/bin/ansible-playbook
12:39:32  #5 8.090   python version = 3.12.6 (main, Sep 11 2024, 08:48:26) [GCC 13.2.1 20240309] (/usr/bin/python3)
12:39:32  #5 8.090   jinja version = 3.1.4
12:39:32  #5 8.090   libyaml = True
12:39:44  #5 DONE 18.4s

12:40:03  Error: Failed preparing provisioner-block "ansible" ""
12:40:03  
12:40:03    on template.pkr.hcl line 46:
12:40:03    (source code not available)
12:40:03  
12:40:03  1 error(s) occurred:
12:40:03  
12:40:03  * Error running "ansible-playbook --version": exit status 5

What does exit status 5 mean? I tried looking through the source for the plugin but the error seemed fairly generic.

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

2 participants