I am trying to create a hosts file with following task. I am running this task on machines completely out of groups['hadoop']. Here I want to create hosts file for nodes from groups['hadoop'] without running my this play on groups['hadoop']
- name: Update /etc/hosts
lineinfile: dest=/etc/hosts
regexp='.*{{ item }}$'
line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}"
state=present
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: groups['hadoop']
tags:
- etc-hosts
I tried this but it didn't work, it worked only when I have groups['hadoop'] in my play hosts.
Anyone know what I am doing wrong here ?