Skip to content

Instantly share code, notes, and snippets.

@frodopwns
Created August 26, 2015 15:32
Show Gist options
  • Save frodopwns/46b138837cc44250c32b to your computer and use it in GitHub Desktop.
Save frodopwns/46b138837cc44250c32b to your computer and use it in GitHub Desktop.
push hostnames to all ansible hosts
- hosts: all
sudo: yes
tasks:
- name: "Build hosts file"
lineinfile:
dest=/etc/hosts
regexp=".*{{ item }}$"
line="{{ hostvars[item].ansible_eth1.ipv4.address }} {{item}}"
state=present
when: hostvars[item].ansible_eth1.ipv4.address is defined
with_items: groups['all']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment