-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpb_ots_deploy_backup.yml
118 lines (89 loc) · 3.41 KB
/
pb_ots_deploy_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
# ##########################################################################################
- name: B A C K U P O N T A P S E L E C T D E P L O Y D A T A
hosts: "localhost"
gather_facts: false
# Edit this section for your environment
vars:
- deploy_login: "admin"
- deploy_pw: "Netapp1!"
- deploy_url: "https://10.0.0.201/api/v3"
- deploy_backup_pw: "{{ deploy_pw }}"
- deploy_backup_dir: "{{ playbook_dir }}/backups/"
- deploy_delete_backup: "DELETE"
# ------------------------------------------------------------------------------------------
tasks:
- name: ..... create backup
uri:
url: "{{ deploy_url }}/backups?fields=*"
method: POST
headers:
Content-Type: "application/json"
body:
password: "{{ deploy_backup_pw }}"
body_format: json
user: "{{ deploy_login }}"
password: "{{ deploy_pw }}"
status_code: 202
validate_certs: false
register: backup_create_response
# ------------------------------------------------------------------------------------------
- name: .....monitor job until "success" or "failure"
uri:
url: "{{ deploy_url }}/jobs/{{ backup_create_response.json.job.id }}"
method: GET
headers:
Content-Type: "application/json"
body_format: json
user: "{{ deploy_login }}"
password: "{{ deploy_pw }}"
status_code: 200
validate_certs: False
register: job_response
until: job_response.json.record.state == "success" or job_response.json.record.state == "failure"
retries: 30
delay: 5
- fail:
msg: "Backup Job Failed: {{ backup_create_response.json.job.id }}"
when:
- job_response.json.record.state == "failure"
# ------------------------------------------------------------------------------------------
- name: .....get download link for backup file
uri:
url: "{{ backup_create_response.location }}?fields=download_url"
method: GET
headers:
Content-Type: "application/json"
user: "{{ deploy_login }}"
password: "{{ deploy_pw }}"
status_code: 200
validate_certs: false
register: backup_url_response
# ------------------------------------------------------------------------------------------
- name: .....verify backup directory exists
file:
path: "{{ deploy_backup_dir }}"
state: directory
# ------------------------------------------------------------------------------------------
- name: .....download backup file
get_url:
url: "{{ backup_url_response.json.record.download_url }}"
dest: "{{ deploy_backup_dir }}"
url_username: "{{ deploy_login }}"
url_password: "{{ deploy_pw }}"
timeout: 180
validate_certs: False
# ------------------------------------------------------------------------------------------
- name: .....delete backup file stored on Deploy server
uri:
url: "{{ backup_create_response.location }}"
method: DELETE
headers:
Content-Type: "application/json"
user: "{{ deploy_login }}"
password: "{{ deploy_pw }}"
status_code: 200
validate_certs: false
register: backup_delete_response
when: deploy_delete_backup == "DELETE"
# ##########################################################################################