2 # To run this play: ansible-playbook playbooks/snapshot-rootnode.yml -l node_standalone
3 - name: Initialize cross play variables
6 - job_wait_to_end: true
8 # Set to false when taking the first snapshot of a new rootnode
10 - snapshot_name: 'base-configuration'
11 - wait_for_changes: true
13 - ansible.builtin.set_fact:
14 job_wait_to_end: "{{job_wait_to_end}}"
15 job_abort: "{{job_abort}}"
16 revert_before: "{{revert_before}}"
17 snapshot_name: "{{snapshot_name}}"
18 target_rootnode: "{{inventory_hostname}}"
19 wait_for_changes: "{{wait_for_changes}}"
21 - name: Shutdown and revert
22 hosts: node_standalone
24 - name: "Find {{target_rootnode}}'s host"
25 ansible.builtin.command:
26 argv: "{{command_args|list}}"
27 register: get_hypervisor
30 - '../scripts/manage_jenkins_node.py'
32 - "{{target_rootnode}}"
33 delegate_to: localhost
34 - ansible.builtin.set_fact:
35 rootnode_host: "{{get_hypervisor.stdout|trim}}"
36 - name: Disable {{target_rootnode}} in Jenkins
37 ansible.builtin.command:
38 argv: "{{command_args | reject('equalto', '') | list}}"
41 - '../scripts/manage_jenkins_node.py'
44 - "{{ 0 if job_wait_to_end else -1}}"
45 - "{{target_rootnode}}"
46 - "{{'--force-abort' if job_abort else ''}}"
48 - 'Ansible play: snapshot rootnode'
49 delegate_to: localhost
50 - name: Revert target rootnode
52 ansible.builtin.command:
53 argv: ['virsh', 'snapshot-revert', "{{target_rootnode}}", '--snapshotname', "{{snapshot_name}}", '--running']
54 delegate_to: "{{rootnode_host}}"
55 - name: Wait for target rootnode to come back online
56 local_action: wait_for host={{ target_rootnode }}
62 # If the playbook isn't run with `-l node_standalone` or `-l ci-rootnode...`, then
63 # this play errors out trying to find variables for the ci-hosts even if the condition
64 # `inventory_hostname in groups.node_standalone` is false.
66 import_playbook: '../site.yml'
67 when: inventory_hostname in groups.node_standalone
69 - name: Cleanup and snapshot
70 hosts: node_standalone
72 - ansible.builtin.debug:
73 msg: "Example playbook command: `ansible-playbook site.yml -l {{target_rootnode}}`"
74 when: wait_for_changes
75 delegate_to: localhost
76 - ansible.builtin.pause:
77 prompt: "Run any playbooks or make other changes against {{target_rootnode}} then hit enter when ready to continue (Ctrl-C to abort)"
78 when: wait_for_changes
79 delegate_to: localhost
80 - name: Remove the jenkins workspace
86 - /home/jenkins/workspace
88 ansible.builtin.command:
89 argv: ['virsh', 'destroy', "{{target_rootnode}}"]
90 delegate_to: "{{rootnode_host}}"
91 - name: Check for existing base snapshot
92 ansible.builtin.shell:
93 cmd: "virsh snapshot-list '{{target_rootnode}}' --name | grep -E '^{{snapshot_name}}$'"
95 register: existing_snapshot
96 delegate_to: "{{rootnode_host}}"
97 - name: Remove existing base snapshot
98 when: existing_snapshot.rc == 0
99 ansible.builtin.command:
100 argv: ['virsh', 'snapshot-delete', '--snapshotname', "{{snapshot_name}}", "{{target_rootnode}}"]
101 delegate_to: "{{rootnode_host}}"
103 ansible.builtin.command:
104 argv: ['virsh', 'snapshot-create-as', '--name', "{{snapshot_name}}", "{{target_rootnode}}"]
105 delegate_to: "{{rootnode_host}}"
107 ansible.builtin.command:
108 argv: ['virsh', 'start', "{{target_rootnode}}"]
109 delegate_to: "{{rootnode_host}}"
110 - name: Enable {{target_rootnode}} in Jenkins
111 ansible.builtin.command:
112 argv: "{{command_args | list}}"
115 - '../scripts/manage_jenkins_node.py'
117 - "{{target_rootnode}}"
118 delegate_to: localhost