Skip to content

Instantly share code, notes, and snippets.

@csmart
Created October 9, 2020 22:32
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 csmart/417e4d66ad790037b5588e2e3040c4a5 to your computer and use it in GitHub Desktop.
Save csmart/417e4d66ad790037b5588e2e3040c4a5 to your computer and use it in GitHub Desktop.
---
- hosts: all
gather_facts: yes
tasks:
- name: Update /etc/hosts to resolve other hosts in inventory
blockinfile:
path: /etc/hosts
state: present
marker: "# {mark} {{ hostvars[item]['inventory_hostname'] }} managed by Ansible task"
block: |-
{{ hostvars[item]['ansible_default_ipv4']['address'] }} {{ hostvars[item]['inventory_hostname'] }}
become: true
with_items: "{{ play_hosts }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment