mirror of
https://github.com/famedly/ansible-collection-base
synced 2024-11-10 06:24:17 +00:00
fix(hostname): ensure hostname is the FQDN
Previously, the value was compared against `ansible_hostname`, which only is the FQDN after the first reboot. This lead to the monitoring not seeing the FQDN as the instance name. This commit scrapes the hostname using the hostname command, which is garantueed to return the current running hostname, and then determines if it needs to be set at runtime.
This commit is contained in:
parent
42744e0f25
commit
2f8e53a6fb
1 changed files with 11 additions and 2 deletions
|
@ -21,8 +21,17 @@
|
|||
{% endfor %}
|
||||
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
||||
|
||||
# Needed because ansibles `ansible_fqdn` is loaded
|
||||
# from /etc/hostname, not from the running hostname
|
||||
- name: Query current hostname
|
||||
command:
|
||||
cmd: "hostname"
|
||||
changed_when: false
|
||||
register: current_hostname
|
||||
|
||||
- name: Set hostname via hostnamectl to avoid a reboot
|
||||
command:
|
||||
cmd: "hostnamectl set-hostname {{ hostname_fqdn }}"
|
||||
when: hostname_fqdn != "{{ ansible_fqdn }}."
|
||||
|
||||
when: hostname_fqdn != hostname_current
|
||||
vars:
|
||||
hostname_current: "{{ current_hostname.stdout }}."
|
||||
|
|
Loading…
Reference in a new issue