-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_host_group.yml
69 lines (58 loc) · 2.05 KB
/
create_host_group.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
---
- name: Create DRO Association
hosts: localhost
vars:
- host_group_dro_name: "{{ 'host_groups'|urlencode }}"
- association_hrefs: []
- puppet_master_dro_name: "{{'puppet_master_server'|urlencode }}"
tasks:
- name: Lookup the "Puppet Master Server" DRO supplied in the dialog
uri:
url: "{{ manageiq.api_url }}/api/generic_objects?expand=resources&filter[]=name='{{ puppet_master_dro_name }}'"
method: GET
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
register: puppet_master_go
- set_fact:
puppet_master_go_href: "{{ puppet_master_go.json.resources[0].href }}"
- name: Find the 'host_groups' DRO Definition
uri:
url: "{{manageiq.api_url }}/api/generic_object_definitions?expand=resources&filter[]=name='{{ host_group_dro_name }}'"
method: GET
validate_certs: no
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
body_format: json
register: host_group_go
- set_fact:
host_group_go_href: "{{ host_group_go.json.resources[0].href }}"
- name: Get the existing host_groups association of the puppet_master_server
uri:
url: "{{ puppet_master_go_href}}?associations=host_groups"
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': item.href } ] }}"
with_items: "{{ associations.json.host_groups }}"
#Post the updated list back to the generic object
- name: Create the corresponding association in the puppet master server back to the host_groups
uri:
url: "{{ puppet_master_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