forked from IBM/z_ansible_collections_samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uri-sample.yml
140 lines (127 loc) · 4.89 KB
/
uri-sample.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
###############################################################################
# © Copyright IBM Corporation 2021
###############################################################################
###############################################################################
# This sample playbook demonstrates basic use cases for invoking a REST API
# service, particularly the z/OSMF REST API services.
#
# Usage:
# ansible-playbook -i <inventory> <playbook>
#
# Example:
# ansible-playbook -i inventories uri-sample.yml
#
###############################################################################
---
- hosts: zos_host
collections:
- ibm.ibm_zos_core
gather_facts: false
environment:
"{{ environment_vars }}"
tasks:
- name: Copy definition file over to target host
zos_copy:
src: "{{ playbook_dir }}/files/{{ ZOSMF_DEFINITION_FILE }}"
dest: "{{ ZOSMF_DEST_FOLDER }}"
force: true
is_binary: true
- name: Query list of available ZOSMF workflows
uri:
url: https://{{ ZOSMF_HOST }}:{{ ZOSMF_PORT }}/zosmf/workflow/rest/{{ ZOSMF_VERSION }}/workflows
user: "{{ ZOSMF_USER }}"
password: "{{ ZOSMF_PASS }}"
method: GET
headers:
Content-Type: application/json
X-CSRF-ZOSMF-HEADER: required_header
force_basic_auth: true
validate_certs: false
status_code: 200
return_content: true
register: zosmf_result
- name: Initialize existing_workflow_key variable
set_fact:
existing_workflow_key: ''
- name: Assign existing_workflow_key variable if the 'sample_uri_workflow' has already been created
set_fact:
existing_workflow_key: "{{ item.workflowKey if 'sample_uri_workflow' in item.workflowName else existing_workflow_key}}"
loop: "{{ zosmf_result.json.workflows }}"
- name: Create workflow if not already created
uri:
url: https://{{ ZOSMF_HOST }}:{{ ZOSMF_PORT }}/zosmf/workflow/rest/{{ ZOSMF_VERSION }}/workflows
user: "{{ ZOSMF_USER }}"
password: "{{ ZOSMF_PASS }}"
method: POST
body_format: json
body:
workflowName: sample_uri_workflow
workflowDefinitionFile: "{{ ZOSMF_DEST_FOLDER }}/{{ ZOSMF_DEFINITION_FILE }}"
system: "{{ ZOSMF_SYSTEM }}"
owner: "{{ ZOSMF_USER }}"
headers:
Content-Type: application/json
X-CSRF-ZOSMF-HEADER: required_header
force_basic_auth: true
validate_certs: false
status_code: 201
return_content: true
register: zosmf_create_result
when: existing_workflow_key == ''
- name: Initialize sample_workflow_key variable for workflow created in previous step (used for starting and cancelling workflow)
set_fact:
sample_workflow_key: ''
- name: Set variable for sample workflow
set_fact:
sample_workflow_key: "{{ zosmf_create_result.json.workflowKey }}"
when: existing_workflow_key == ''
# Initiates the Starter_Automated_Step in the sample_definition_file.xml
- name: Start workflow after creation
uri:
url: https://{{ ZOSMF_HOST }}:{{ ZOSMF_PORT }}/zosmf/workflow/rest/{{ ZOSMF_VERSION }}/workflows/{{ sample_workflow_key }}/operations/start
user: "{{ ZOSMF_USER }}"
password: "{{ ZOSMF_PASS }}"
method: PUT
headers:
Content-Type: application/json
X-CSRF-ZOSMF-HEADER: required_header
force_basic_auth: true
validate_certs: false
status_code: 202
return_content: true
register: zosmf_start_result
when: sample_workflow_key != ''
- name: Cancel workflow after starting
uri:
url: https://{{ ZOSMF_HOST }}:{{ ZOSMF_PORT }}/zosmf/workflow/rest/{{ ZOSMF_VERSION }}/workflows/{{ existing_workflow_key }}/operations/cancel
user: "{{ ZOSMF_USER }}"
password: "{{ ZOSMF_PASS }}"
method: PUT
headers:
Content-Type: application/json
X-CSRF-ZOSMF-HEADER: required_header
force_basic_auth: true
validate_certs: false
status_code: 200
return_content: true
register: zosmf_cancel_result
when: existing_workflow_key != ''
- name: Delete workflow if already created
uri:
url: https://{{ ZOSMF_HOST }}:{{ ZOSMF_PORT }}/zosmf/workflow/rest/{{ ZOSMF_VERSION }}/workflows/{{ existing_workflow_key }}
user: "{{ ZOSMF_USER }}"
password: "{{ ZOSMF_PASS }}"
method: DELETE
headers:
Content-Type: application/json
X-CSRF-ZOSMF-HEADER: required_header
force_basic_auth: true
validate_certs: false
status_code: 204
return_content: true
register: zosmf_delete_result
when: existing_workflow_key != ''
- name: Remove definition file
file:
path: "{{ ZOSMF_DEST_FOLDER }}/{{ ZOSMF_DEFINITION_FILE }}"
state: absent