0

我在 Packer 中使用 ansible-local 配置程序,并尝试使用 community.general 集合,但是我根本无法让我的剧本看到它。

打包机代码是:

{
  "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`}}"
}

集合似乎在正确的 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'

然而,Ansible 无法使用它

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.

有问题的 Anisble 游戏是

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

任何关于我在哪里出错的建议都会很棒....

4

1 回答 1

1

这是因为我使用的是 Ansible 2.9,并且该功能仅在 2.10 中出现(这将教会我不要检查我正在阅读的文档版本:D)。

羞耻的 Ansible 错误提到如果无法使用集合,则会丢失集合......

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

希望这个问题可以帮助处于类似位置的其他人。

于 2021-02-09T09:34:58.473 回答