Skip to content

Commit

Permalink
Add ip_address variable for setting fqdn on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmeszaros authored and holms committed Jan 22, 2019
1 parent 884889a commit 6a0ec6a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
fqdn: "{{ inventory_hostname }}"
hostname: "{{ inventory_hostname_short }}"
ip_address: "{{ ansible_default_ipv4.address }}"
6 changes: 3 additions & 3 deletions tasks/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6a0ec6a

Please sign in to comment.