-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.yml
66 lines (59 loc) · 2.78 KB
/
backup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
- name: Backup the Undercloud image
hosts: hypervisor
gather_facts: yes
any_errors_fatal: true
vars:
undercloud: "{{ hostvars[(groups.undercloud|first)].inventory_hostname }}"
undercloud_image_file: "{{ install.snapshot.filename.rstrip('.qcow2') }}.qcow2"
tasks:
- name: install package with virt-sparsify
package:
name: libguestfs-tools-c
state: present
- block:
- name: shutdown the undercloud VM
virt:
name: "{{ undercloud }}"
state: destroyed
- name: copy and shrink undercloud image
command: "virt-sparsify --compress {{ install.disk.pool }}/{{ undercloud }}-disk1.qcow2 {{ undercloud_image_file }}"
- name: copy our auth key to the virthost
copy:
src: "{{ install.dest.key | expanduser | realpath }}"
dest: "~/backup_server_auth_key"
mode: "0400"
when: install.dest|default({})
- name: copy the image to remote server
shell: |
scp -o StrictHostKeyChecking=no -o PreferredAuthentications=publickey -o UserKnownHostsFile=/dev/null -i \
~/backup_server_auth_key {{ undercloud_image_file }} {{ install.dest.user }}@{{ install.dest.address }}:{{install.dest.path}}/{{ undercloud_image_file }}
when: install.dest|default({})
tags: skip_ansible_lint
- name: copy the image to mirror server
shell: |
date
scp -o StrictHostKeyChecking=no -o PreferredAuthentications=publickey -o UserKnownHostsFile=/dev/null -i \
~/backup_server_auth_key {{ undercloud_image_file }} {{ install.dest.user }}@{{ install.dest.mirror.address }}:{{ install.dest.mirror.path }}/{{ undercloud_image_file }}
date
when: install.dest.mirror|default({})
tags: skip_ansible_lint
always:
- name: cleanup the undercloud image file
file:
path: "{{ undercloud_image_file }}"
state: absent
when: install.dest|default({})
- name: cleanup in case of failure
shell: |
ssh -i ~/backup_server_auth_key {{ install.dest.user }}@{{ install.dest.address }} rm -f {{install.dest.path}}/{{ undercloud_image_file }}
when:
- local_hash is defined
- remote_hash is defined
- local_hash.stdout != remote_hash.stdout
tags: skip_ansible_lint
- name: Power on the undercloud VM
virt:
name: "{{ undercloud }}"
state: running
# TODO(yfried): accept a destination to push image to, and cleanup. Use ansible modules instead
# of hard-coded scp