-
Notifications
You must be signed in to change notification settings - Fork 3
/
environments_engine_versions_retrieve.yml
103 lines (81 loc) · 3.54 KB
/
environments_engine_versions_retrieve.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
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
---
- name: retrieve environments
hosts: controlhub
#
# Retrieve the available Environments and Engine Versions from the DataOps control hub.
#
# Displays the environment name, ID, type for environments of type SELF, Other types, such as AWS are not displayed.
# Displays the engine type ID which includes engine type, version
# Instructions for use:
#
# 1. user must paste the CRED_ID and CRED_TOKEN or set them as environment variables
#
# 2. ansible-playbook -i hostsfile_controlhub environments_engine_versions_retrieve.yml
vars:
# ENVIRONMENT VARIABLES
STREAMSETS_RETRIEVE_ENV_URL: >-
{{ STREAMSETS_SCH_URL }}/provisioning/rest/v1/csp/environments
STREAMSETS_RETRIEVE_ENG_URL: >-
{{ STREAMSETS_SCH_URL }}/provisioning/rest/v1/csp/engineVersions/
STREAMSETS_RETRIEVE_HEADERS: {
"X-Requested-By": "User",
"X-SS-REST-CALL": "true",
"X-SS-App-Auth-Token": "{{CRED_TOKEN}}",
"X-SS-App-Component-Id": "{{CRED_ID}}",
"Content-type": "application/json",
}
tasks:
# --------------------------------------------------------------------------------
- name: SECTION 1 - RETRIEVE ENVIRONMENTS STEP 1.1 run retrieve environments curl command
uri:
url: "{{ STREAMSETS_RETRIEVE_ENV_URL }}"
method: GET
return_content: yes
status_code: 200
headers: "{{ STREAMSETS_RETRIEVE_HEADERS }}"
register: json_response
- name: STEP 1.2 isolate env_records and convert each line from json to dict
set_fact:
env_record_json: "{{ json_response.content }}"
- name: STEP 1.3 Pull data from each line and print all the Name, ID and type of environments for environments with type matching SELF
ansible.builtin.debug:
msg: "Environment Name,ID,Type: {{ item.name, item.id, item.type if item.type=='SELF' }}"
loop:
"{{ env_record_json.data }}"
when:
"item.type=='SELF'"
- name: STEP 1.4 Make a copy paste line for the environment variable
ansible.builtin.debug:
msg: "export STREAMSETS_ENV_ID={{ item.id }}"
loop:
"{{ env_record_json.data }}"
when:
"item.type=='SELF'"
- name: STEP 1.5 Pull data from each line and print all the Name, ID and type of environments for environments with type matching SELF
set_fact:
environment_id_matching: "{{ environment_id_matching | default([]) + [ item.id ] }}"
loop:
"{{ env_record_json.data }}"
when:
"item.type=='SELF'"
# --------------------------------------------------------------------------------
# --------------------------------------------------------------------------------
- name: SECTION 2 - STEP 2.1 run retrieve engine versions curl command
uri:
url: "{{ STREAMSETS_RETRIEVE_ENG_URL }}"
method: GET
return_content: yes
status_code: 200
headers: "{{ STREAMSETS_RETRIEVE_HEADERS }}"
register: json_response
- name: STEP 2.2 extract lines of data as json
set_fact:
eng_record: "{{ json_response.content }}"
- name: STEP 2.3 Set engineversion data ID and version if we are not filtering by engine type and version
set_fact:
engine_version_id_matching: "{{ engine_version_id_matching | default([]) + [ item.id ] }}"
loop: "{{ eng_record.data }}"
- name: STEP 2.4 print engineversion data ID and version
ansible.builtin.debug:
msg: "{{ engine_version_id_matching }}"
# --------------------------------------------------------------------------------