--- /dev/null
+---
+- 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