ansible: Add play to snapshot rootnodes
[lttng-ci.git] / automation / ansible / playbooks / snapshot-rootnode.yml
1 ---
2 - hosts: localhost
3 vars:
4 # Useful for taking the first snapshot of a new rootnode
5 - revert_before: true
6 vars_prompt:
7 - name: target_rootnode
8 private: false
9 - name: rootnode_host
10 private: false
11 - name: snapshot_name
12 default: 'base-configuration'
13 private: false
14 vars_files:
15 - ../vars/ci-instances.yml
16 tasks:
17 # - Set a maintenance on the jenkins node
18 # - Wait until the task is done
19 # - Maybe interrupt the jenkins tasks
20 - name: Revert target rootnode
21 when: revert_before
22 ansible.builtin.command:
23 argv: ['virsh', 'snapshot-revert', "{{target_rootnode}}", '--snapshotname', "{{snapshot_name}}", '--running']
24 delegate_to: "{{rootnode_host}}"
25 - name: Wait for target rootnode to come back online
26 local_action: wait_for host={{ target_rootnode }}
27 port=22
28 delay=1
29 timeout=300
30 state=started
31 - ansible.builtin.pause:
32 prompt: "Run any playbooks or make other changes against {{target_rootnode}} then hit enter when ready to continue (Ctrl-C to abort)"
33 - name: Remove the jenkins workspace
34 ansible.builtin.file:
35 path: "{{item}}"
36 state: absent
37 with_items:
38 - /root/workspace
39 - /home/jenkins/workspace
40 delegate_to: "{{target_rootnode}}"
41 - name: Stop the VM
42 ansible.builtin.command:
43 argv: ['virsh', 'destroy', "{{target_rootnode}}"]
44 delegate_to: "{{rootnode_host}}"
45 - name: Check for existing base snapshot
46 ansible.builtin.shell:
47 cmd: "virsh snapshot-list '{{target_rootnode}}' --name | grep -E '^{{snapshot_name}}$'"
48 ignore_errors: true
49 register: existing_snapshot
50 delegate_to: "{{rootnode_host}}"
51 - name: Remove existing base snapshot
52 when: existing_snapshot.rc == 0
53 ansible.builtin.command:
54 argv: ['virsh', 'snapshot-delete', '--snapshotname', "{{snapshot_name}}", "{{target_rootnode}}"]
55 delegate_to: "{{rootnode_host}}"
56 - name: Snapshot
57 ansible.builtin.command:
58 argv: ['virsh', 'snapshot-create-as', '--name', "{{snapshot_name}}", "{{target_rootnode}}"]
59 delegate_to: "{{rootnode_host}}"
60 - name: Start the vm
61 ansible.builtin.command:
62 argv: ['virsh', 'start', "{{target_rootnode}}"]
63 delegate_to: "{{rootnode_host}}"
64 # - Remove maintenance on the jenkins node
This page took 0.030669 seconds and 4 git commands to generate.