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:
transcaffeine 2021-04-19 09:01:14 +02:00
parent 42744e0f25
commit 2f8e53a6fb
No known key found for this signature in database
GPG key ID: 03624C433676E465

View file

@ -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 }}."