Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How do I loop over a list of hosts in a group, inside of a template?



How do I loop over a list of hosts in a group, inside of a template?..

Answer / Baldev Singh

To loop over a list of hosts in a group and use that list within a template in Ansible, you can use the with_items loop module:n1. Define your group: In your inventory, define a group containing the hosts you want to loop through.nExample:ngroup:n - host1n - host2n - host3nn2. Use the with_items loop in a task: Inside a play or role, use the with_items loop module to loop over the hosts in your group and pass the current host to a template.nExample:n- name: Render a template for each hostn hosts: alln tasks:n - name: Loop through hosts and render templaten template: src=mytemplate.j2 dest=/etc/myconfig.confn with_items: '{{ groups.mygroup }}'

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Ansible Interview Questions

How do I access shell environment variables?

1 Answers  


What is the ask_pass module in ansible?

1 Answers  


What is ansible tower?

1 Answers  


How do I see a list of all of the ansible_ variables?

1 Answers  


How do I see all the inventory vars defined for my host?

1 Answers  


Talk about ansible architecture.

1 Answers  


How do I handle python pathing not having a python 2.x in /usr/bin/python on a remote machine?

1 Answers  


What are the ansible modules? Explain the different types.

1 Answers  


Compare ansible vs puppet?

1 Answers  


What is ansible task?

1 Answers  


Explain the concept behind infrastructure as code (iac).

1 Answers  


How do I generate crypted passwords for the user module?

1 Answers  


Categories