summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Fennell <matthew@fennell.dev>2025-08-10 21:21:58 +0100
committerMatthew Fennell <matthew@fennell.dev>2025-08-10 21:21:58 +0100
commit0ab318fcd287cfca56dc220811019db7a7373a25 (patch)
treee745a52352270eecbfd904bad0ff68c2ccfba1bb
parentb4e956593b393884598e7d8b177463e08224c970 (diff)
Set hostname in playbook
Some services, such as munin, read the hostname from the system, and don't allow "virtual host" configuration like prosody. For such services, we want to make sure the hostname is set correctly.
-rw-r--r--files/hosts.j211
-rw-r--r--playbook.yaml14
2 files changed, 25 insertions, 0 deletions
diff --git a/files/hosts.j2 b/files/hosts.j2
new file mode 100644
index 0000000..65ab310
--- /dev/null
+++ b/files/hosts.j2
@@ -0,0 +1,11 @@
+# SPDX-FileCopyrightText: 2025 Matthew Fennell <matthew@fennell.dev>
+#
+# SPDX-License-Identifier: AGPL-3.0-only
+
+127.0.1.1 {{ hostname }}
+127.0.0.1 localhost
+
+# The following lines are desirable for IPv6 capable hosts
+::1 localhost ip6-localhost ip6-loopback
+ff02::1 ip6-allnodes
+ff02::2 ip6-allrouters
diff --git a/playbook.yaml b/playbook.yaml
index 06f75e0..2c8ea28 100644
--- a/playbook.yaml
+++ b/playbook.yaml
@@ -61,6 +61,20 @@
mode: "0644"
become: true
+ - name: Ensure hostname is set
+ ansible.builtin.hostname:
+ name: "{{ hostname }}"
+ become: true
+
+ - name: Ensure hostname is configured in /etc/hosts
+ ansible.builtin.template:
+ src: "{{ playbook_dir }}/files/hosts.j2"
+ dest: /etc/hosts
+ owner: root
+ group: root
+ mode: "0644"
+ become: true
+
- name: Retrieve DANE hash
ansible.builtin.shell:
cmd: >