Using set_facts and with_items together in Ansible

There is a workaround which may help. You may “register” results for each set_fact iteration and then map that results to list: — – hosts: localhost tasks: – name: set fact set_fact: foo_item=”{{ item }}” with_items: – four – five – six register: foo_result – name: make a list set_fact: foo=”{{ foo_result.results | map(attribute=”ansible_facts.foo_item”) | … Read more

How to copy files between two nodes using ansible

As ant31 already pointed out you can use the synchronize module to this. By default, the module transfers files between the control machine and the current remote host (inventory_host), however that can be changed using the task’s delegate_to parameter (it’s important to note that this is a parameter of the task, not of the module). … Read more

How can I use Ansible nested variable?

Per Ansible FAQ: Another rule is ‘moustaches don’t stack’. We often see this: {{ somevar_{{other_var}} }} The above DOES NOT WORK, if you need to use a dynamic variable use the hostvars or vars dictionary as appropriate: {{ hostvars[inventory_hostname][‘somevar_’ + other_var] }} So in your case: – debug: msg={{hostvars[inventory_hostname][Component].community_release_num}} Or: – debug: msg={{vars[Component].community_release_num}} Or (since … Read more

ansible command to list all known hosts

–list-hosts lists hosts that match a –limit. The input is the -i, inventory. Your inventory is a file named hosts, which doesn’t exist. You need to create or generate an inventory file from somewhere. Ansible can’t intuit what your inventory is.