-
-
Save coolpalani/289a125557535d249aa42e5638f6cda1 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 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