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 to interpolate variables or dynamic variable names?

Answer Posted / Sumit Khari

In Ansible, you can use the 'with_items' and 'set_fact' constructs to iterate over a list of variables and set dynamic variable names. For example: - name: Create vars for hosts with specific facts with_items: "{{ ansible_facts['hostvars']['localhost']['ansible_os_family'] }}" tasks: - set_fact: os_name: "{{ item }}" when: ansible_os_family == item

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a playbook to create a backup of a file in the remote servers before copy.

2


How to install ansible?

2


Compare ansible vs puppet?

2


How should one configure a jump host to access servers that I have no direct access to?

2


What is configuration management and how does it help an organization?

2


What is the best way to make content reusable/redistributable?

2


How to create encrypted files using ansible?

3


Why is ‘{{ }}’ notation used?

3


How ansible works?

2


When should I use {{ }}? Also, how to interpolate variables or dynamic variable names

2


Compare ansible with chef.

2


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

2


How can you access a list of ansible_variables?

3


What are ad-hoc commands? Give an example.

3


What is ansible role and how are they different from the playbook?

2