I've been trying to get Ansible Tower to run a playbook/role which should
update the /etc/hosts file across all hosts in a group.
I have the following playbook:
- name: Update hosts file if required
hosts: all
gather_facts: yes
roles:
- { role: hostfile }
and the following role:
---
- debug: var=ansible_default_ipv4.address
- name: node to ip mapping
debug: var=hostvars[item].ansible_default_ipv4.address
with_items: groups['all']
It you check your output you will see that your item i literally the string groups['all']. But you need to write this as a variable
with_items: "{{ groups['all'] }}"
However, when Tower run this its skips the 2 hosts in the group. From
looking at the debug output it would appear that Tower is not caching the
facts under hostvars as you can see from the output below: