Ansible:'item'是未定义的

我正在尝试使用with_itemsdelegate_to在多个主机上运行Docker容器。 我在/etc/ansible/hosts有一个组test

 [test] my_machine1 my_machine2 

而这个任务:

  - name: Run app container docker: name: "{{artifact_id}}" insecure_registry: true image: "{{image}}:{{version}}" pull: always state: reloaded ports: - "{{port_mapping}}" delegate_to: '{{item}}' with_items: - "{{groups['test']}}" 

但是当我运行它,我得到这个错误:

{“failed”:true,“msg”:“ERROR!”item'undefined“}

我究竟做错了什么?

提前致谢

你需要照顾一下。 delegate_towith_items是任务的一部分,而不是docker模块的一部分。

 - name: Run app container docker: name: "{{artifact_id}}" insecure_registry: true image: "{{image}}:{{version}}" pull: always state: reloaded ports: - "{{port_mapping}}" delegate_to: '{{item}}' with_items: "{{groups['test']}}" 

虽然我不确定你的代表团会在这里工作。 为什么需要首先委托它的背景是什么? 正常的方法是将这个剧本应用到组test的主机上。 我想你是对本地主机运行的戏剧?

另一个不相关的事情:我遇到的问题与docker模块pull: alwaysstate: reloaded一起使用state: reloaded 与docker-compose不同,docker模块总是会重新启动容器,而不pipe是否有更新的图片被拖拽。


 - hosts: localhost tasks: - download nexus - build image - upload to registry - ... - hosts: test tasks: - docker: ...