docker-composeansiblepackeransible-galaxy

ansible-local in packer wont pickup collections


I am using an ansible-local provisioner in Packer, and trying to use the community.general collection, however I cannot get my playbook to see it at all.

The Packer code is:

{
  "type": "ansible-local",
  "staging_directory": "/tmp/packer-provisioner-ansible-local",
  "command": "ANSIBLE_COLLECTIONS_PATHS=/tmp/packer-provisioner-ansible-local/collections/roles ansible-playbook",
  "playbook_file": "{{ user `jenkins_workspace` }}/packer/ansible/playbook.yml",
  "playbook_dir": "{{ user `jenkins_workspace` }}/packer/ansible",
  "galaxy_command": "ANSIBLE_COLLECTIONS_PATHS=/tmp/packer-provisioner-ansible-local/collections/roles ansible-galaxy collection",
  "galaxy_file": "{{ user `jenkins_workspace` }}/packer/ansible/collections/requirements.yml",
  "inventory_groups": "{{user `inventory_groups`}}"
}

The collections seems to install no problem in the correct DIR

amazon-ebs: Executing Ansible Galaxy: cd /tmp/packer-provisioner-ansible-local && ANSIBLE_COLLECTIONS_PATHS=/tmp/packer-provisioner-ansible-local/roles ansible-galaxy collection install -r /tmp/packer-provisioner-ansible-local/requirements.yml -p /tmp/packer-provisioner-ansible-local/roles
amazon-ebs: |Installing 'community.general:2.0.0' to '/tmp/packer-provisioner-ansible-local/roles/ansible_collections/community/general'

However then Ansible is unable to use it

amazon-ebs: Executing Ansible: cd /tmp/packer-provisioner-ansible-local && ANSIBLE_COLLECTIONS_PATHS=/tmp/packer-provisioner-ansible-local/roles ansible-playbook /tmp/packer-provisioner-ansible-local/playbook.yml --extra-vars "packer_build_name=amazon-ebs packer_builder_type=amazon-ebs packer_http_addr=ERR_HTTP_ADDR_NOT_IMPLEMENTED_BY_BUILDER -o IdentitiesOnly=yes"  -c local -i /tmp/packer-provisioner-ansible-local/packer-provisioner-ansible-local801906075
amazon-ebs: ERROR! couldn't resolve module/action 'community.general.docker_compose'. This often indicates a misspelling, missing collection, or incorrect module path.

The Anisble play in question is

    - name: Docker compose build the containers
      community.general.docker_compose:
        recreate: never
        pull: yes
        build: yes
        state: present
        stopped: yes
        project_src: "{{ home }}"

Any advice on where I am going wrong with this would be great....


Solution

  • This is because I was using Ansible 2.9 and the feature only came in at 2.10 (that'll teach me to not check the docs version I am reading :D ).

    Shame the Ansible error mentions collections being missing if it cant use them...

    ERROR! couldn't resolve module/action 'community.general.docker_compose'. This often indicates a misspelling, missing collection, or incorrect module path.
    

    Hopefully the question might help others in a similar position.