ansible-demo-retwis/os_update_etc_hosts.yml
2024-03-07 22:38:24 +01:00

14 lines
527 B
YAML

---
- name: Static DNS Lookup
hosts: all
gather_facts: true
become: true
tasks:
- name: Add all hosts to /etc/hosts
ansible.builtin.lineinfile:
dest: /etc/hosts
regexp: "^{{ hostvars[item]['ansible_facts']['default_ipv4']['address'] }}.+{{ hostvars[item].ansible_facts.fqdn }}.*$"
line: "{{ hostvars[item]['ansible_facts']['default_ipv4']['address'] }} {{ hostvars[item].ansible_facts.fqdn }} {{ hostvars[item].ansible_facts.hostname }}"
state: present
with_items: "{{ groups.all }}"