Skip to content

Instantly share code, notes, and snippets.

@carlessanagustin
Forked from rothgar/main.yml
Last active June 7, 2018 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlessanagustin/bc6cbc062a9e0f3230010393ea808b57 to your computer and use it in GitHub Desktop.
Save carlessanagustin/bc6cbc062a9e0f3230010393ea808b57 to your computer and use it in GitHub Desktop.
ANSIBLE: Generate /etc/hosts with Ansible from https://gist.github.com/rothgar/8793800
---
- hosts: all
gather_facts: yes
tasks:
- name: Update /etc/hosts
become: true
tags:
- dns
lineinfile:
dest: /etc/hosts
regexp: '.*{{ item }}$'
line: "{{ hostvars[item].ansible_default_ipv4.address }} {{ hostvars[item].inventory_hostname }} {{ hostvars[item].ansible_fqdn }}"
state: present
when: hostvars[item].ansible_default_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