-
Notifications
You must be signed in to change notification settings - Fork 107
/
upload_via_rsync.yml
74 lines (64 loc) · 2.06 KB
/
upload_via_rsync.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
67
68
69
70
71
72
73
74
---
# Invoke with (example):
#- set_fact:
# artifacts:
# - {{ recovery_source_dir }}/artifact1
# - {{ recovery_source_dir }}/artifact2
- name: Assert that the "artifacts" fact is defined and valid
assert:
that:
- artifacts is defined
- artifacts is sequence
- artifacts | length > 0
fail_msg: The "artifacts" fact must be defined and must be a non-empty list.
- name: Upload artifacts from mounted storage
delegate_to: "{{ recovery_source_host }}"
always:
- name: Delete generated files
file:
path: "{{ item }}"
state: absent
loop:
- "{{ private_key_file.path }}"
- "{{ private_key_file.path }}.pub"
- delegate_to: "{{ inventory_hostname }}" # cancel previous delegate_to
block:
- name: Remove public openssh key from admin's authorized_keys
authorized_key:
user: "{{ admin_user.name }}"
state: absent
key: >-
{{ openssh_keypair.public_key }}
block:
- name: Create a temporary file path to hold the private key in
tempfile:
path: ~/.ssh/
suffix: .tmp
state: file
register: private_key_file
- name: Generate openssh keypair for rsync over ssh
openssh_keypair:
path: "{{ private_key_file.path }}"
size: 2048
force: true
register: openssh_keypair
- delegate_to: "{{ inventory_hostname }}" # cancel previous delegate_to
block:
- name: Add public openssh key to admin's authorized_keys
authorized_key:
user: "{{ admin_user.name }}"
state: present
key: >-
{{ openssh_keypair.public_key }}
- name: Ensure destination directory for artifacts exists
file:
path: "{{ recovery_dir }}/"
state: directory
- name: Use rsync to copy all artifacts
synchronize:
mode: push
dest: "{{ recovery_dir }}/"
src: "{{ item }}"
checksum: true
private_key: "{{ private_key_file.path }}"
loop: "{{ artifacts }}"