Skip to content

Commit 926f794

Browse files
committed
Update Blog “how-to-use-dscc-api-and-ansible-to-collect-the-storage-configuration”
1 parent e856bb3 commit 926f794

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

content/blog/how-to-use-dscc-api-and-ansible-to-collect-the-storage-configuration.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,107 @@ Capturing the current storage configuration in order to verify it against best p
1616

1717

1818

19+
```
20+
- name: Include encrypted vars
21+
include_vars: credentials.yml
22+
23+
- name: Get Access Token
24+
ansible.builtin.uri:
25+
url: "{{ sso_url }}"
26+
headers:
27+
Content-Type: "application/x-www-form-urlencoded"
28+
Authorization: "Basic {{ (dscc_id + ':' + dscc_secret) | b64encode }}"
29+
method: POST
30+
body: "grant_type=client_credentials"
31+
validate_certs: false
32+
register: oauth_response
33+
34+
- name: Define header
35+
ansible.builtin.set_fact:
36+
token: "Bearer {{ oauth_response.json.access_token }}"
37+
38+
- name: Store Token
39+
ansible.builtin.copy:
40+
content: "{{ token }}"
41+
dest: 'vars/token.txt'
42+
mode: "0644"
43+
```
44+
45+
46+
47+
48+
1949
## DSCC REST API call
2050

2151

2252

53+
```
54+
- name: Include encrypted vars
55+
include_vars: vars/credentials.yml
56+
57+
- name: Get Access Token
58+
ansible.builtin.set_fact:
59+
token: "{{ lookup('file', 'vars/token.txt') }}"
60+
61+
- name: Check the Methood
62+
ansible.builtin.fail:
63+
msg: "DSCC-API-CALL: RestAPI Method is not defined!"
64+
when: method is not defined
65+
66+
- name: Check for the request Uri
67+
ansible.builtin.fail:
68+
msg: "DSCC-API-Call: Request URI is not defined!"
69+
when: request_uri is not defined
70+
71+
- name: DSCC Command - {{request_uri}}
72+
ansible.builtin.uri:
73+
url: "{{ base_url }}{{ request_uri }}"
74+
headers:
75+
Authorization: "{{ token }}"
76+
Content-Type: "application/json"
77+
method: "{{ method }}"
78+
validate_certs: false
79+
status_code: [200, 201, 202, 401, 404]
80+
register: result
81+
when: body is not defined
82+
83+
- name: Set result status
84+
ansible.builtin.set_fact:
85+
status: "{{ result.status }}"
86+
tmpres: "{{ result }}"
87+
when: body is not defined
88+
89+
- name: DSCC Command with body {{request_uri}}
90+
ansible.builtin.uri:
91+
url: "{{ base_url }}{{ request_uri }}"
92+
headers:
93+
Authorization: "{{ token }}"
94+
Content-Type: "application/json"
95+
method: "{{ method }}"
96+
body_format: json
97+
body: "{{ body | to_json }}"
98+
validate_certs: false
99+
status_code: [200, 201, 202, 400, 401, 404]
100+
register: result2
101+
when: body is defined
102+
103+
- name: Set result status
104+
ansible.builtin.set_fact:
105+
status: "{{ result2.status }}"
106+
tmpres: "{{ result2 }}"
107+
when: body is defined
108+
109+
- name: Set response when status in [200, 201, 202, 401]
110+
ansible.builtin.set_fact:
111+
response: "{{ tmpres }}"
112+
when: status in ['200', '201', '202','401']
113+
114+
- name: Undefine Response when status not in [200...]
115+
ansible.builtin.set_fact:
116+
response: ""
117+
when: status not in ['200', '201', '202','401']
118+
```
119+
120+
121+
23122
# Gathering the storage configuration

0 commit comments

Comments
 (0)