Packer

Error running ansible provisioner in Packer

Adding this provisioner in to a json packer template gave a rather unhelpful error:

        {
            "type": "ansible",
            "user": "ec2-user",
            "playbook_file": "ansible/main.yml"

        }

The syntax for the provisioner is correct, but clearly something was wrong. I could not find anything in my code which was calling the –version:-

  
[Container] 2018/10/11 15:24:16 Command did not exit successfully ansible-playbook --version exit status 1

Python3 was being installed along with pip from the system repos, and pip updated from the python repos before ansible is installed wth pip3. Due to the errors, several checks were written in, such as the which ansible-playbook. The latest addition was the key, running - ansible-playbook –version from within the shell provisioner:-

      - apt-get update && apt-get install -y python3 python3-pip
      - pip3 install --upgrade setuptools
      - pip3 install ansible
      - which ansible-playbook
      - echo "Show the files on builder system  ................................................."
      - pwd
      - ls -lart
      - ls -lart ansible/
      - ansible-playbook --version

The output from CodeBuild console was:-

[Container] 2018/10/11 15:24:16 Running command ansible-playbook --version
ERROR: Ansible requires a minimum of Python2 version 2.6 or Python3 version 3.5. Current version: 3.4.3 (default, Nov 28 2017, 16:41:13) [GCC 4.8.4]

The key looks like the python version is not high enough to support Ansible….. AWS supported releases are available at https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html

What I think was happenning was the error message written out from the shell provisioner part was hidden by the Ansible provisioner, and just the error code written out, hence just the exit status 1.


rb/packer.txt · Last modified: 12/10/2018 09:56 by andrew