---
- name: Update Network
when: ("inventory_hostname == inventory_hostname_short" and gateway == 10.10.10.1)
I don't know what I need to do to replace the HOSTNAME=inventory_hostname_short with HOSTNAME=inventory_hostname. I basically want to replace the HOSTNAME statement with the FQDN.
Also, does that when statement look right?
TIA
I would use the lineinfile module. A rough draft (untested) without
correct indentation:
- name: "Ensure FQDN is present"
lineinfile:
dest=/etc/sysconfig/network
line="HOSTNAME={{ ansible_fqdn }}"
regexp="^HOSTNAME=.*"
- name: "Replace hostname with FQDN"
lineinfile:
dest=/etc/sysconfig/network
line="HOSTNAME={{ ansible_fqdn }}"
regexp="^HOSTNAME=.*"
state=present
You might need to compare the FQDN to the short hostname and then if they match create a new one (presumably you know what domain name to add to the end)
Equally you could replace the hostname with a created one each time as it won't change anything if the result woild be the same. Unless you are potentially using multiple domain names I would just do that,