-
Notifications
You must be signed in to change notification settings - Fork 20
/
adhoc-deprovision-onevm-ci.yml
67 lines (64 loc) · 2.15 KB
/
adhoc-deprovision-onevm-ci.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
- hosts: localhost
become: no
gather_facts: no
vars:
- one_api_url: http://localhost:2633
tasks:
# The playbook consumes structures of this form passed in by the mechanism
# in the Ansible variable `duffy_in`:
#
# duffy_in ->
# {
# "nodes": [
# {
# "id": 1,
# "hostname": "...",
# "ipaddr": "...",
# "data": {"provision": {"id": 1, ...}}
# },
# {
# "id": 2,
# "hostname": "...",
# "ipaddr": "...",
# "data": {"provision": {"id": 2, ...}}
# },
# ...
# ]
# }
#
# The data.provision field of a node contains the result returned for that
# node from the provisioning playbook and should contain all necessary
# information to perform the deprovisioning (e.g. a machine id specific to
# the used cloud management software).
# This task emulates deprovisioning the nodes, its result can be arbitrary
# in principle, but ...
- name: "Deprovision the things!"
delegate_to: "{{ one_controller_host }}"
one_vm:
api_username: "{{ one_api_username }}"
api_password: "{{ one_api_password }}"
api_url: "{{ one_api_url }}"
hard: yes
state: absent
instance_ids: >-
{{ duffy_in.nodes | json_query(nodes_id_query) }}
register: one_vm_result
vars:
nodes_id_query: "[*].data.provision.opennebula.id"
# ... this (mandatory) task has to be able to transform it into the
# expected output format, i.e. set a fact `duffy_out` which repeats enough
# of data.provision passed into the playbook for each successfully
# deprovisioned node to clearly correlate results with node objects so
# Duffy can chalk up nodes for reuse, or mark them as retired or failed
# appropriately.
#
# duffy_out ->
# {
# "nodes": [{"id": 1, ...}, {"id": 2, ...}]
# }
- name: "Summarize the things!"
set_fact:
duffy_out:
nodes: "{{ duffy_in.nodes | json_query(one_vm_result_query) }}"
vars:
one_vm_result_query: "[*].data.provision"