-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlb_generic_objects.yaml
More file actions
124 lines (110 loc) · 3.3 KB
/
lb_generic_objects.yaml
File metadata and controls
124 lines (110 loc) · 3.3 KB
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
---
- name: Create DRO Association
hosts: localhost
vars:
- lb_class: "{{ 'lb_class'|urlencode }}"
- lb_name: "{{ 'lb_name'|urlencode }}"
- lb_type: "{{ 'lb_type'|urlencode }}"
- lb_id: "{{ 'lb_id'|urlencode }}"
- association_hrefs: []
tasks:
- name: Create "Load Balancer" DRO supplied in the dialog
uri:
url: "{{ manageiq.api_url }}/api/generic_object_definitions"
method: POST
validate_certs: no
body_format: json
body:
action: create
name: "{{ lb_class }}"
properties:
attributes:
id: integer
name: string
type: string
associations:
service: vms
provider: Vm
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
- name: Lookup the "Load Balancer" DRO supplied in the dialog
uri:
url: "{{ manageiq.api_url }}/api/generic_objects?expand=resources&filter[]=name='{{ lb_class }}'"
method: GET
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
register: lb_class_go
- set_fact:
lb_class_go_href: "{{ lb_class_go.json.resources[0].href }}"
- name: Create "LB" DRO Definition
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: "{{ lb_name }}"
properties:
attributes:
id: "{{ lb_id }}"
name: "{{ lb_name }}"
type: "{{ lb_type }}"
associations:
service: vms
provider: Vm
- name: Find the "LB" DRO Definition
uri:
url: "{{manageiq.api_url }}/api/generic_objects?expand=resources&filter[]=name='{{ lb_name }}'"
method: GET
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
register: lb_go
- set_fact:
lb_go_href: "{{ lb_go.json.resources[0].href }}"
- name: Get the existing load balancers association of the lb_class
uri:
url: "{{ lb_go_href}}?associations={{ lb_name }}"
method: GET
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
register: associations
#Extract the existing association hrefs into their own list
- set_fact:
association_hrefs: "{{ association_hrefs + [ { 'href': lb_go_href } ] }}"
#Post the updated list back to the generic object
- name: Create the corresponding association in the lb class back to the load balancer
uri:
url: "{{ lb_class_go_href }}"
method: POST
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
body:
action: edit
associations:
host_groups:
"{{ association_hrefs }}"
register: output
- name: Add generic object to 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: "{{ lb_go.json.results[0].href }}"