-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcreate_firewall_action_sIT.yml
165 lines (140 loc) · 4.71 KB
/
create_firewall_action_sIT.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
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
---
- name: Create Firewall Action
hosts: localhost
vars:
- firewall_action_dro_name: "{{ 'Firewall Action'|urlencode }}"
- association_hrefs: []
tasks:
- name: Change the service name
uri:
url: "{{ manageiq.api_url }}/api/{{ manageiq.service }}"
method: POST
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
body:
action: edit
resource:
name: "{{ ipaddress }}"
description: "Firewall Action {{ ipaddress }}"
register: output
- name: Find the "Firewall Action" DRO definition
uri:
url: "{{ manageiq.api_url }}/api/generic_object_definitions?expand=resources&filter[]=name='{{ firewall_action_dro_name }}'"
method: GET
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
register: action_dro_definition
- set_fact:
action_dro_definition_href: "{{ action_dro_definition.json.resources[0].href }}"
#- debug: var=action_dro_definition_href
- name: Lookup the "Firewall Group" DRO supplied in the dialog
uri:
url: "{{ manageiq.api_url }}/api/generic_objects?expand=resources&filter[]=name='{{ firewall_group_name|urlencode }}'"
method: GET
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
register: group_dro
- set_fact:
group_dro_href: "{{ group_dro.json.resources[0].href }}"
#- debug: var=group_dro_href
- name: Lookup the requesting user
uri:
url: "{{ manageiq.api_url }}/api/{{ manageiq.user }}"
method: GET
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
register: requester
- set_fact:
requester_name: "{{ requester.json.name | default('') }}"
requester_email: "{{ requester.json.email | default('') }}"
- name: Lookup the user's group
uri:
url: "{{ manageiq.api_url }}/api/{{ manageiq.group }}"
method: GET
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
register: requester_group
- set_fact:
group_description: "{{ requester_group.json.description | default('') }}"
- name: Create "Firewall Action" DRO entry
uri:
url: "{{ manageiq.api_url }}/api/generic_objects"
method: POST
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
body:
action: create
name: "{{ ipaddress }}"
generic_object_definition:
href: "{{ action_dro_definition_href }}"
property_attributes:
requester_department: "{{ group_description }}"
requester: "{{ requester_name }}"
requester_email: "{{ requester_email }}"
service_id: "{{ manageiq.service.split('/')[1] }}"
associations:
firewall_group:
- href: "{{ group_dro_href }}"
register: action_dro
#- debug: var=action_dro.json
- set_fact:
action_dro_href: "{{ action_dro.json.results[0].href }}"
- debug: var=action_dro_href
- name: Get the existing firewall_actions associations of the Firewall Group
uri:
url: "{{ group_dro_href }}?associations=firewall_actions"
method: GET
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
register: associations
# Extract the exiting association hrefs into their own list
- set_fact:
association_hrefs: "{{ association_hrefs + [ { 'href': item.href } ] }}"
with_items: "{{ associations.json.firewall_actions }}"
- debug: var=association_hrefs
# Add the new association href to the lost
- set_fact:
association_hrefs: "{{ association_hrefs + [ { 'href': action_dro_href } ] }}"
- debug: var=association_hrefs
- name: Create the corresponding association in the Firewall Group back to the new action
uri:
url: "{{ group_dro_href }}"
method: POST
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
body:
action: edit
associations:
firewall_actions:
"{{ association_hrefs }}"
register: output
- name: Register firewall action with the service
uri:
url: "{{ manageiq.api_url }}/api/{{ manageiq.service }}"
method: POST
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
body:
action: add_resource
resource:
resource:
href: "{{ action_dro_href }}"
register: output