-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadd_single_vm_to_service.yml
45 lines (38 loc) · 1.21 KB
/
add_single_vm_to_service.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
---
- hosts: localhost
tasks:
- debug: var=manageiq.api_url
- debug: var=manageiq.api_token
- debug: var=manageiq.service
- debug: var=manageiq.event_target
- name: Set the Service URL
set_fact:
svc_url: "/api/{{ manageiq.service }}"
- name: Set the VM URL
set_fact:
vm_url: "/api/{{ manageiq.event_target }}"
- debug: var=svc_url
- name: Create an array of vms
set_fact:
vms: "{{ vms|default([]) + [ { 'href': svc_url, 'resource': { 'href': item } } ] }}"
with_items:
- "{{ vm_url }}"
- debug: var=vms
- name: Register vms with the service
uri:
url: "{{ manageiq.api_url }}/api/services"
method: POST
body_format: json
body:
action: add_resource
resources : "{{ vms }}"
validate_certs: False
headers:
X-Auth-Token: "{{ manageiq.api_token }}"
Content-Type: "application/json"
status_code: 200
register: output
- debug: var=output.json.results[0].success
- name: Check if the VM was successfully attached to service
fail: msg="{{output.json.results[0].message}}"
when: output.json.results[0].success == false