-
-
Save anudeepmk/da2cf3633d9c872f03a2d5b72f884544 to your computer and use it in GitHub Desktop.
Ansible automatically create /etc/hosts file for all host - to give nice short names using dnsmasq
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 | |
tasks: [] | |
- hosts: all | |
gather_facts: True | |
tasks: | |
- name: check connection | |
ping: | |
- name: setup | |
setup: | |
- name: "Build hosts file" | |
lineinfile: dest=/etc/hosts | |
state=present | |
dest=/etc/hosts | |
regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" | |
when: hostvars[item].ansible_default_ipv4.address is defined | |
with_items: "{{ groups['all'] }}" | |
- hosts: localhost | |
gather_facts: True | |
tasks: | |
- name: check connection | |
ping: | |
- name: setup | |
setup: | |
- name: "Build hosts file" | |
lineinfile: dest=/etc/hosts | |
state=present | |
dest=/etc/hosts | |
regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" | |
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