Loop the Hosts in Ansible Playbook with_item or with any condition

141 views
Skip to first unread message

aditya varma

unread,
Oct 13, 2014, 3:57:51 AM10/13/14
to ansible...@googlegroups.com
Want to pass a json variables containing couple of ansible hosts to a ansible-playbook so the variables can be looped in for hosts one by one.similar to


---
 - hosts: "{{ item.sample.server }}"
   sudo: true
   tasks:
   - name: print
     debug: msg= "{{ item.sample.jar }} is being deployed to {{ item.sample.server }}" 
   - {include: /home/ubuntu/deployment/deployment.yml, "{{item}}" : ["{{ item.sample.jar }}", "{{ item.sample.server }}"]}
   with_items: "{{ item }}"

by passing variable by 

   ansible-playbook play.yml --extra-vars 'item=[{"sample":{"server":"server1"}},{"sample":{"server":"server2"}}]'

Marc Patermann

unread,
Oct 15, 2014, 6:13:42 AM10/15/14
to ansible...@googlegroups.com
aditya,

aditya varma schrieb (13.10.2014 09:57 Uhr):
> Want to pass a json variables containing couple of ansible hosts to a
> ansible-playbook so the variables can be looped in for hosts one by
> one.similar to
I think I do not understand clearly what you really want, but:
Can't you just use "hosts" for the hosts you want to loop over, like it
is intendet to and - if the action should run on another server - use
the delegate_to option?
http://docs.ansible.com/playbooks_delegation.html#delegation

Marc
Reply all
Reply to author
Forward
0 new messages