-
Notifications
You must be signed in to change notification settings - Fork 0
/
130.2_playbook_add_k8s_policy_and_rule.yaml
176 lines (171 loc) · 5.81 KB
/
130.2_playbook_add_k8s_policy_and_rule.yaml
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Example Playbok to Add Kubernetes Cluster to PPDM
- name: Add K8S to PPDM
hosts: localhost
gather_facts: no
connection: local
vars_files:
- ./vars/main.yml
vars:
k8s_policy_name: K8S_Protection 3hrs 3days
tasks:
- name: Checking Required Variable ppdm_fqdn
fail:
msg: "We do not have ppdm_fqdn set !"
when: (ppdm_fqdn is not defined) or (ppdm_fqdn|length <= 8)
- name: Checking Required Variables
fail:
msg: "We do not have ppdm_new_password set !"
when: (ppdm_new_password is not defined) or (ppdm_new_password|length == 0)
- name: Checking Required Variable ddve_fqdn
fail:
msg: "We do not have ddve_fqdn set !"
when: (ddve_fqdn is not defined) or (ddve_fqdn|length == 0)
- name: Setting Base URL
set_fact:
ppdm_baseurl: "https://{{ ppdm_fqdn | regex_replace('^https://') }}"
- name: Get PPDM Token for https://{{ ppdm_fqdn | regex_replace('^https://') }}
include_role:
name: get_ppdm_token
vars:
ppdm_password: "{{ ppdm_new_password }}"
- debug:
msg: "{{ access_token }}"
verbosity: 1
name: do we have a token ?
- name: Get Protection Policy with filter
vars:
filter: 'name eq "{{ k8s_policy_name }}"'
include_role:
name: get_ppdm_protection_policy
- set_fact:
protection_policy: "{{ protection_policy[0] }}"
when: protection_policy[0] is defined
- debug:
msg: "{{ protection_policy }}"
verbosity: 0
- name: Get DataDomain Storage Systems
include_role:
name: get_ppdm_storage-systems
vars:
filter: type eq "DATA_DOMAIN_SYSTEM" and details.dataDomain.preferredInterfaces.ipAddress eq "{{ ddve_fqdn }}"
when: protection_policy.id is not defined
- name: Create New Protection Policy
vars:
new_protection_policy:
id:
name: "{{ k8s_policy_name }}"
description: 'This is a GTO Demo Kubernetes Protection Policy'
assetType: KUBERNETES
type: ACTIVE
category: CENTRALIZED_PROTECTION
targetStorageProvisionStrategy: AUTO_PROVISION
enabled: true
passive: false
forceFull: false
priority: 1
credentials:
encrypted: false
dataConsistency: CRASH_CONSISTENT
complianceInterval:
details:
stages:
- id: "{{ 1000 | random | to_uuid | upper }}" #99227db6-8bfc-38e1-d333-f63d740d2880
type: PROTECTION
passive: false
retention:
interval: 3
unit: DAY
storageSystemRetentionLock: false
extendedRetentions:
- retention:
interval: 3
unit: DAY
storageSystemRetentionLock: false
selector:
backupType: SYNTHETIC_FULL
target:
storageSystemId: "{{ storagesystems[0].id }}"
preferredInterfaceId: "{{ storagesystems[0].details.dataDomain.preferredInterfaces[0].networkName }}"
attributes:
protection: {}
operations:
- type: AUTO_FULL
schedule:
frequency: HOURLY
startTime: '2022-01-24T19:00:00Z'
duration: PT10H
interval: 3
backupType: SYNTHETIC_FULL
filterIds: []
include_role:
name: new_ppdm_protection_policy
when: protection_policy.id is not defined and (storagesystems[0] is defined)
- debug:
msg: "{{ protection_policy }}"
verbosity: 0
when: protection_policy is defined #and (protection_policy.id is not defined)
- name: Get Protection rule with filter
vars:
filter: 'name eq "Kubernetes Namespace Label Rule {{ ppdm_rule }}"'
# filter: 'name eq "Kubernetes Namespace Label Rule ppdm_policy=PPDM_GOLD"'
include_role:
name: get_ppdm_protection_rules
when: protection_policy.id is defined
- set_fact:
protection_rule: "{{ protection_rule[0] }}"
when: protection_rule[0].id is defined
- debug:
msg: "{{ protection_rule }}"
verbosity: 0
when: protection_rule is defined
- name: Create New Protection Rule
vars:
new_protection_rule:
name: Kubernetes Namespace Label Rule {{ ppdm_rule }}
category: COMPOUND
rules:
- category: PRIMITIVE
conditions:
- assetAttributeName: userTags
operator: EQUALS
assetAttributeValue: "{{ ppdm_rule }}"
assetAttributeValues:
- "{{ ppdm_rule }}"
conditionConnector: AND
logicalOperator: AND
inventorySourceType: KUBERNETES
priority: -1
tenant:
id: 00000000-0000-4000-a000-000000000000
action: MOVE_TO_GROUP
actionResult: "{{ protection_policy.id }}"
conditions:
- assetAttributeName: userTags
operator: EQUALS
assetAttributeValue: "{{ ppdm_rule }}"
assetAttributeValues:
- "{{ ppdm_rule }}"
conditionConnector: OR
logicalOperator: OR
inventorySourceType: KUBERNETES
priority: 1
tenant:
id: 00000000-0000-4000-a000-000000000000
include_role:
name: new_ppdm_protection_rule
when: protection_policy.id is defined and protection_rule.id is not defined
- debug:
msg: "{{ protection_rule }}"
verbosity: 0
when: protection_rule is defined
# when: protection_policy.id is defined or (protection_rule is not defined and protection_policy[0].id is defined )
- name: Run Protection Rule
vars:
inventorySourceType: "{{ protection_rule.inventorySourceType }}"
include_role:
name: run_ppdm_protection_rule
when: protection_rule.inventorySourceType is defined
- debug:
msg: "{{ protection_rule_run }}"
verbosity: 1
when: protection_rule.inventorySourceType is defined