docker - Ansible: 'item' is undefined -


i'm trying use with_items delegate_to run docker container in several hosts. have group test in /etc/ansible/hosts:

[test] my_machine1 my_machine2 

and task:

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

but when run it, error:

{"failed": true, "msg": "error! 'item' undefined"}

what doing wrong?

thanks in advance

you need take care of indention. delegate_to , with_items part of task, not of docker module.

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

though i'm not sure delegation work here. background why need delegate in first place? normal way apply play hosts of group test. guess you're instead running play against localhost?

another unrelated thing: experienced issues docker module when pull: always used state: reloaded. unlike docker-compose, docker module always restart container no matter if there updated image pulled or not.


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

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -