ansible: Add optional play to replace common hostname patterns during release-ugprades
authorKienan Stewart <kstewart@efficios.com>
Thu, 15 Jun 2023 14:07:37 +0000 (10:07 -0400)
committerKienan Stewart <kstewart@efficios.com>
Tue, 20 Jun 2023 15:18:55 +0000 (11:18 -0400)
Change-Id: Id60d624b91fd6e66347017f337b4048a319ac1c5

automation/ansible/playbooks/release-upgrade.yml

index aeeeb136c5ef688027b4ba8fb4c6c7560678cf30..fcc2d70c025835b5163b60ce894511ff3ef34477 100644 (file)
           with_items:
             - "/var/backups/pre-{{next_release}}-backup.tgz"
             - "/var/backups/dpkg-selections-pre-{{next_release}}.txt"
+- name: Update hostname
+  hosts: all
+  vars:
+    # eg. ansible-playbook -e '{"UPDATE_HOSTNAME":true}' playbooks/release-upgrade.yml
+    update_hostname: "{{lookup('vars', 'UPDATE_HOSTNAME', default='false')}}"
+  tasks:
+    - debug:
+        msg: "update_hostname: {{update_hostname}}"
+    - replace:
+        path: /etc/hostname
+        regexp: "{{ansible_distribution_release}}"
+        replace: "{{next_release}}"
+      when: update_hostname | bool
+    - replace:
+        path: /etc/hostname
+        regexp: "deb{{ansible_distribution_version}}"
+        replace: "deb{{ansible_distribution_version|int + 1 }}"
+      when: update_hostname | bool and ansible_distribution == 'Debian'
 - name: Debian major version upgrade
   hosts: all
   vars:
This page took 0.023645 seconds and 4 git commands to generate.