mirror of
https://github.com/famedly/ansible-collection-base
synced 2024-11-10 06:24:17 +00:00
chore(hostname): use handler for on-demand hostname setting
This commit is contained in:
parent
d95eec5f19
commit
e9e6fec5da
2 changed files with 6 additions and 18 deletions
5
roles/hostname/handlers/main.yml
Normal file
5
roles/hostname/handlers/main.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
- name: "Set hostname via hostnamectl to avoid a reboot"
|
||||
command:
|
||||
cmd: "hostnamectl set-hostname {{ hostname_fqdn }}"
|
||||
when: ansible_os_family in ["Debian"]
|
||||
listen: "set-hostname"
|
|
@ -8,6 +8,7 @@
|
|||
content: |
|
||||
{{ hostname_fqdn }}
|
||||
tags: ["deploy", "deploy-hostname"]
|
||||
notify: "set-hostname"
|
||||
|
||||
- name: "Ensure /etc/hosts contains all hostnames and aliases of the server"
|
||||
blockinfile:
|
||||
|
@ -21,21 +22,3 @@
|
|||
{% endfor %}
|
||||
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
||||
tags: ["deploy", "deploy-hostname"]
|
||||
|
||||
# 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
|
||||
check_mode: false
|
||||
register: "current_hostname"
|
||||
tags: ["deploy", "deploy-hostname"]
|
||||
|
||||
- name: "Set hostname via hostnamectl to avoid a reboot"
|
||||
command:
|
||||
cmd: "hostnamectl set-hostname {{ hostname_fqdn }}"
|
||||
when: "hostname_fqdn != hostname_current"
|
||||
vars:
|
||||
hostname_current: "{{ current_hostname.stdout }}."
|
||||
tags: ["deploy", "deploy-hostname"]
|
||||
|
|
Loading…
Reference in a new issue