-
Notifications
You must be signed in to change notification settings - Fork 11
/
vRA-destroy-VM.yml
61 lines (54 loc) · 1.75 KB
/
vRA-destroy-VM.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
---
- hosts: localhost
# Defining used variable
vars:
VRA_HOST: {{ VRA_HOST}}
VRA_USER: {{ VRA_USER }}
VRA_PASS: {{ VRA_PASS }}
VRA_TENANT: {{ VRA_TENANT }}
USER_REQUESTEDFOR: {{ VRA_USER }}@{{ VRA_HOST}}
DESCRIPTION: {{ DESCRIPTION }}
REASON: {{ REASON }}
CPU_COUNT: {{ CPU_COUNT }}
MEMORY_SIZE: {{ MEMORY_SIZE }}
user_data:
tasks:
- uri:
url: https://{{ VRA_HOST }}/identity/api/tokens
method: POST
HEADER_Content-Type: application/json
HEADER_Accept: application/json
body: '{ "username" : "{{ VRA_USER }}", "" : "{{ VRA_PASS }}", "" : "{{ VRA_TENANT }}" }'
validate_certs: no
return_content: yes
HEADER_Content-Type: application/json
register: token
# send a inventory request to VERA
- uri:
url: https://{{ VRA_HOST }}/catalog-service/api/consumer/entitledCatalogItems
method: GET
HEADER_Content-Type: application/json
HEADER_Accept: application/json
HEADER_authorization: Bearer {{ token.json['id'] }}
validate_certs: no
return_content: yes
register: list
- debug: var=list
- command: " sed -i {{ item }} /etc/ansible/roles/destroy.json"
with_items:
- s/##DESTROY_ID##/{{ DESTROY_ID }}/g
- set_fact: body_json="{{ lookup('template','/etc/ansible/roles/destroy.json',convert_data=False) }}"
- debug: var=body_json
- uri:
url: https://{{ VRA_HOST }}/catalog-service/api/consumer/requests
method: POST
HEADER_Accept: application/json
HEADER_Content-Type: "application/json"
HEADER_authorization: Bearer {{ token.json['id'] }}
body: "{{ body_json }}"
validate_certs: no
timeout: 30
status_code: 201
return_content: yes
register: result
- debug: var=result