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
Write a playbook to create a backup of a file in the remote servers before copy.
How to install ansible?
Compare ansible vs puppet?
How should one configure a jump host to access servers that I have no direct access to?
What is configuration management and how does it help an organization?
What is the best way to make content reusable/redistributable?
How to create encrypted files using ansible?
Why is ‘{{ }}’ notation used?
How ansible works?
When should I use {{ }}? Also, how to interpolate variables or dynamic variable names
Compare ansible with chef.
How do I see a list of all of the ansible_ variables?
How can you access a list of ansible_variables?
What are ad-hoc commands? Give an example.
What is ansible role and how are they different from the playbook?