ctucx.git: ansible-configs

My personal ansible roles and playbooks

commit 82c7fc63730451155b051edd30d14bd6f93771c7
parent 626f29e511b6dfbace1b7558568326c359a3ca09
Author: Leah Thein <leah@toaster.fritz.box>
Date: Sat, 5 Dec 2020 13:38:35 +0100

common: set hostname only if changed
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/roles/common/tasks/network.yml b/roles/common/tasks/network.yml
@@ -18,15 +18,17 @@
     dest: /etc/resolv.conf
     mode: 0755
 
-- name: set hostname
-  hostname:
-    name: "{{network.hostname}}"
-    use: alpine
-
 - name: "create file: /etc/hostname"
   copy:
     content: "{{network.hostname}}"
     dest: /etc/hostname
+  register: hostname
+
+- name: Change hostname of running system
+  hostname:
+    name: "{{network.hostname}}"
+    use: alpine
+  when: hostname.changed
 
 - name: enable NAT support
   ansible.posix.sysctl: