From: Kienan Stewart Date: Fri, 26 Jul 2024 20:51:57 +0000 (-0400) Subject: ansible: Disable, wait, and enable root nodes during snapshot X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=aca12d81747f9c631f12ae08441c8eafe7c02365;p=lttng-ci.git ansible: Disable, wait, and enable root nodes during snapshot This change decreases the number of manual steps required to perform the updates to the rootnode snapshots. Change-Id: I0ad25a4e282498ce5f146f75dcabaa84a6eb2400 Signed-off-by: Kienan Stewart --- diff --git a/automation/ansible/README.md b/automation/ansible/README.md index fac4b7c..be764c4 100644 --- a/automation/ansible/README.md +++ b/automation/ansible/README.md @@ -41,12 +41,14 @@ ansible-playbook -i hosts [-l SUBSET] site.yaml ## CI 'rootnode' -1. Add an entry to the `vms` variable in the host vars for a libvirt host +1. Add the new ansible node to the `node_standalone` group in the inventory +2. Add an entry to the `vms` variable in the host vars for the libvirt host * See the defaults and details in `roles/libvirt/vars/main.yml` and `roles/libvirt/tasks/main.yml` * Make sure to set the `cdrom` key to the path of ISO for the installer -2. Run the playbook, eg. `ansible-playbook -i hosts -l cloud07.internal.efficios.com site.yml` +3. Run the playbook, eg. `ansible-playbook -i hosts -l cloud07.internal.efficios.com site.yml` * The VM should be created and started -3. Once the VM is installed take a snapshot so that Jenkins may revert to the original state +4. Once the VM is installed take a snapshot so that Jenkins may revert to the original state + * `ansible-playbook playbooks/snapshot-rootnode.yml -e '{"revert_before": false}' -l new-rootnode` ### Ubuntu auto-installer diff --git a/automation/ansible/playbooks/snapshot-rootnode.yml b/automation/ansible/playbooks/snapshot-rootnode.yml index 9b17bc7..91809a7 100644 --- a/automation/ansible/playbooks/snapshot-rootnode.yml +++ b/automation/ansible/playbooks/snapshot-rootnode.yml @@ -1,22 +1,52 @@ --- -- hosts: localhost +# To run this play: ansible-playbook playbooks/snapshot-rootnode.yml -l node_standalone +- name: Initialize cross play variables + hosts: node_standalone vars: - # Useful for taking the first snapshot of a new rootnode + - job_wait_to_end: true + - job_abort: false + # Set to false when taking the first snapshot of a new rootnode - revert_before: true - vars_prompt: - - name: target_rootnode - private: false - - name: rootnode_host - private: false - - name: snapshot_name - default: 'base-configuration' - private: false - vars_files: - - ../vars/ci-instances.yml + - snapshot_name: 'base-configuration' + - wait_for_changes: true tasks: - # - Set a maintenance on the jenkins node - # - Wait until the task is done - # - Maybe interrupt the jenkins tasks + - ansible.builtin.set_fact: + job_wait_to_end: "{{job_wait_to_end}}" + job_abort: "{{job_abort}}" + revert_before: "{{revert_before}}" + snapshot_name: "{{snapshot_name}}" + target_rootnode: "{{inventory_hostname}}" + wait_for_changes: "{{wait_for_changes}}" + +- name: Shutdown and revert + hosts: node_standalone + tasks: + - name: "Find {{target_rootnode}}'s host" + ansible.builtin.command: + argv: "{{command_args|list}}" + register: get_hypervisor + vars: + command_args: + - '../scripts/manage_jenkins_node.py' + - 'get_hypervisor' + - "{{target_rootnode}}" + delegate_to: localhost + - ansible.builtin.set_fact: + rootnode_host: "{{get_hypervisor.stdout|trim}}" + - name: Disable {{target_rootnode}} 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}}" + - "{{target_rootnode}}" + - "{{'--force-abort' if job_abort else ''}}" + - '--reason' + - 'Ansible play: snapshot rootnode' + delegate_to: localhost - name: Revert target rootnode when: revert_before ansible.builtin.command: @@ -28,8 +58,25 @@ delay=1 timeout=300 state=started + +# If the playbook isn't run with `-l node_standalone` or `-l ci-rootnode...`, then +# this play errors out trying to find variables for the ci-hosts even if the condition +# `inventory_hostname in groups.node_standalone` is false. +- name: Run site.yml + import_playbook: '../site.yml' + when: inventory_hostname in groups.node_standalone + +- name: Cleanup and snapshot + hosts: node_standalone + tasks: + - ansible.builtin.debug: + msg: "Example playbook command: `ansible-playbook site.yml -l {{target_rootnode}}`" + when: wait_for_changes + delegate_to: localhost - ansible.builtin.pause: prompt: "Run any playbooks or make other changes against {{target_rootnode}} then hit enter when ready to continue (Ctrl-C to abort)" + when: wait_for_changes + delegate_to: localhost - name: Remove the jenkins workspace ansible.builtin.file: path: "{{item}}" @@ -37,7 +84,6 @@ with_items: - /root/workspace - /home/jenkins/workspace - delegate_to: "{{target_rootnode}}" - name: Stop the VM ansible.builtin.command: argv: ['virsh', 'destroy', "{{target_rootnode}}"] @@ -61,4 +107,12 @@ ansible.builtin.command: argv: ['virsh', 'start', "{{target_rootnode}}"] delegate_to: "{{rootnode_host}}" - # - Remove maintenance on the jenkins node + - name: Enable {{target_rootnode}} in Jenkins + ansible.builtin.command: + argv: "{{command_args | list}}" + vars: + command_args: + - '../scripts/manage_jenkins_node.py' + - 'enable' + - "{{target_rootnode}}" + delegate_to: localhost