diff --git a/README.md b/README.md index e61d4b3..8b96604 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Role Variables |---------------|----------------|---------| |*hostname* | hostname (eg. vm1) | `inventory_hostname_short` | |*fqdn* | domain name (eg. vm1.test.com) | `inventory_hostname` | +|*ip_address* | ip address (eg. 192.168.0.20) | `ansible_default_ipv4.address` | Example ------- diff --git a/defaults/main.yml b/defaults/main.yml index 710a5cc..9bc8083 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1,4 @@ --- fqdn: "{{ inventory_hostname }}" hostname: "{{ inventory_hostname_short }}" +ip_address: "{{ ansible_default_ipv4.address }}" diff --git a/tasks/linux.yml b/tasks/linux.yml index e31bd7c..2710b84 100644 --- a/tasks/linux.yml +++ b/tasks/linux.yml @@ -13,11 +13,11 @@ - name: Build hosts file (backups will be made) lineinfile: dest: /etc/hosts - regexp: "^{{ ansible_default_ipv4.address }}" - line: "{{ ansible_default_ipv4.address }} {{ fqdn }} {{ hostname }}" + regexp: "^{{ ip_address }}" + line: "{{ ip_address }} {{ fqdn }} {{ hostname }}" state: present backup: yes - when: ansible_default_ipv4.address is defined + when: ip_address is defined notify: - restart hostname - restart systemd-logind