From: Kienan Stewart Date: Fri, 4 Oct 2024 14:59:22 +0000 (-0400) Subject: ansible: Add play to update non-standalone CI nodes X-Git-Url: http://git.lttng.org./?a=commitdiff_plain;h=848ece49523f6b16b006f63e2313c60260614249;p=lttng-ci.git ansible: Add play to update non-standalone CI nodes Change-Id: I7ca97377786a9f348c5273590d857c81b51dd635 Signed-off-by: Kienan Stewart --- diff --git a/automation/ansible/playbooks/update-node.yml b/automation/ansible/playbooks/update-node.yml new file mode 100644 index 0000000..664b745 --- /dev/null +++ b/automation/ansible/playbooks/update-node.yml @@ -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