Created
August 14, 2017 06:44
-
-
Save nitanka/5976ef7fd51c8795db91c4c35f290a44 to your computer and use it in GitHub Desktop.
Ansible: adding hosts to /etc/hosts from inventory file
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
name: host mapping /etc/hosts of server | |
hosts: <hostgroup> | |
become: true | |
tasks: | |
- name: adding hostname mapping /etc/hosts | |
lineinfile: | |
dest: /etc/hosts | |
insertbefore: '^127.0.0.1' | |
line: '{{ item.0 }} {{ item.1 }}' | |
with_together: | |
- "{{ groups['hostname'] | map('extract', hostvars, ['ansible_default_ipv4', 'address'])| list }}" | |
- "{{ groups['hostname'] | map('extract', hostvars, ['ansible_nodename']) | list }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment