-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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