hashicorp / packer-plugin-ansible

Packer plugin for Ansible Provisioner
https://www.packer.io/docs/provisioners/ansible
Mozilla Public License 2.0
49 stars 36 forks source link

Ansible fails to run inside the hashicorp/packer docker image #200

Open thunderpants73 opened 1 week ago

thunderpants73 commented 1 week ago

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 commented 4 days ago

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 commented 4 days ago

@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 commented 4 days ago

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 commented 4 days ago

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.