From 1b8f7afacfe2e30a52e075f75cfd7e20a0200d9d Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Wed, 4 Sep 2024 14:08:20 +0200 Subject: [PATCH] use ansible_default_ipv4 fact if possible when writing /etc/hosts --- roles/etc_hosts/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/etc_hosts/tasks/main.yml b/roles/etc_hosts/tasks/main.yml index e0f3f8c68..c4086f92e 100644 --- a/roles/etc_hosts/tasks/main.yml +++ b/roles/etc_hosts/tasks/main.yml @@ -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