ansible: Add play to update non-standalone CI nodes
authorKienan Stewart <kstewart@efficios.com>
Fri, 4 Oct 2024 14:59:22 +0000 (10:59 -0400)
committerKienan Stewart <kstewart@efficios.com>
Fri, 4 Oct 2024 16:27:49 +0000 (12:27 -0400)
Change-Id: I7ca97377786a9f348c5273590d857c81b51dd635
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
automation/ansible/playbooks/update-node.yml [new file with mode: 0644]

diff --git a/automation/ansible/playbooks/update-node.yml b/automation/ansible/playbooks/update-node.yml
new file mode 100644 (file)
index 0000000..664b745
--- /dev/null
@@ -0,0 +1,92 @@
+---
+- hosts: node:!node_standalone
+  vars:
+    - job_wait_to_end: true
+    - job_abort: false
+    - wait_for_changes: true
+  tasks:
+    - name: Initialize variables
+      ansible.builtin.set_fact:
+        job_wait_to_end: "{{job_wait_to_end}}"
+        job_abort: "{{job_abort}}"
+        wait_for_changes: "{{wait_for_changes}}"
+
+    - name: Disable {{ansible_hostname}} in Jenkins
+      ansible.builtin.command:
+        argv: "{{command_args | reject('equalto', '') | list}}"
+      vars:
+        command_args:
+          - '../scripts/manage_jenkins_node.py'
+          - 'disable'
+          - '--wait'
+          - "{{ 0 if job_wait_to_end else -1}}"
+          - "{{ansible_hostname}}"
+          - "{{'--force-abort' if job_abort else ''}}"
+          - '--reason'
+          - 'Ansible play: update-node'
+      delegate_to: localhost
+      retries: 3
+
+    - name: Update apt cache
+      when: ansible_os_family == 'Debian'
+      ansible.builtin.apt:
+        state: latest
+        update_cache: true
+        upgrade: yes
+
+    - name: Update dnf
+      when: ansible_os_family in ['RedHat', 'Rocky']
+      ansible.builtin.dnf:
+        state: latest
+        update_cache: true
+        update_only: true
+
+    - name: Update zypper
+      when: ansible_os_family == 'Suse'
+      ansible.builtin.zypper:
+        name: '*'
+        state: latest
+        update_cache: true
+
+    - name: Update apk
+      when: ansible_os_family == 'Alpine'
+      ansible.builtin.apk:
+        state: latest
+        update_cache: true
+        upgrade: true
+
+# If the playbook isn't run with `-l node:!node_standalone` or similar, then
+# this play errors out trying to find variables for the ci-hosts even if the condition
+# `inventory_hostname in groups.node` is false.
+- name: Run site.yml
+  import_playbook: '../site.yml'
+  when: inventory_hostname in groups.node and inventory_hostname not in groups.node_standalone
+
+- name: Cleanup
+  hosts: node:!node_standalone
+  tasks:
+    - ansible.builtin.debug:
+        msg: "Example playbook command: `ansible-playbook site.yml -l {{ansible_hostname}}`"
+      when: wait_for_changes
+      delegate_to: localhost
+    - ansible.builtin.pause:
+        prompt: "Run any playbooks or make other changes against {{ansible_hostname}} then hit enter when ready to continue (Ctrl-C to abort)"
+      when: wait_for_changes
+      delegate_to: localhost
+    - name: Remove the jenkins workspace
+      when: not job_wait_to_end
+      ansible.builtin.file:
+        path: "{{item}}"
+        state: absent
+      with_items:
+        - /root/workspace
+        - /home/jenkins/workspace
+    - name: Enable {{ansible_hostname}} in Jenkins
+      ansible.builtin.command:
+        argv: "{{command_args | list}}"
+      vars:
+        command_args:
+          - '../scripts/manage_jenkins_node.py'
+          - 'enable'
+          - "{{ansible_hostname}}"
+      delegate_to: localhost
This page took 0.023584 seconds and 4 git commands to generate.