Skip to content

Commit

Permalink
use ansible_default_ipv4 fact if possible when writing /etc/hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni authored and ehelms committed Oct 29, 2024
1 parent 4c4a24b commit 695c225
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion roles/etc_hosts/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
lineinfile:
dest: /etc/hosts
regexp: ".*{{ item.replace('.', '-') }}$"
line: "{{ hostvars[item].ansible_host }} {{ item.replace('.', '-') }}.{{ etc_hosts_domain }} {{ item.replace('.', '-') }}"
line: "{{ hostvars[item]['ansible_facts']['ansible_default_ipv4']['address'] | default(hostvars[item].ansible_host) }} {{ item.replace('.', '-') }}.{{ etc_hosts_domain }} {{ item.replace('.', '-') }}"
state: present
when: hostvars[item].ansible_host is defined
become: yes
Expand Down

0 comments on commit 695c225

Please sign in to comment.