this is the code I created and the response we are getting is something like this
---
- name: Get media_server response
hosts: localhost
gather_facts: no
tasks:
- name: Pushing the generated configuration file to Media Server (sfconnect)
shell: "curl -X PUT -H 'Username: AWSSUsername1' -H 'Password: AWSSPassword1' '[https://URL/awss-services/rest/v1/media/rgnet/rxg_gateways?'keepFileName=true](https://URL/awss-services/rest/v1/media/rgnet/rxg_gateways?%27keepFileName=true) -F 'file=@test_config_1.txt'"
args:
warn: no
register: mediasvr_resp
ignore_errors: true
- name: debug the upgrade_response
debug:
var: mediasvr_resp
- name: print the response code
debug:
msg: "{{ mediasvr_resp.stdout }}"
when: mediasvr_resp.stdout is defined
the response is :
ok: [localhost] => {
"msg": {
"changed": true,
"cmd": "curl -X PUT -H 'Username: AWSSUsername1' -H 'Password: AWSSPassword1' 'https://URL/awss-services/rest/v1/media/rgnet/rxg_gateways?keepFileName=true' -F 'file=@/tmp/test_config_1.txt'",
"delta": "0:00:00.076243",
"end": "2023-10-13 02:43:30.159288",
"failed": false,
"msg": "",
"rc": 0,
"start": "2023-10-13 02:43:30.083045",
"stderr": " % Total % Received % Xferd Average Speed Time Time Time Current\n Dload Upload Total Spent Left Speed\n\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r100 362 100 162 100 200 2571 3174 --:--:-- --:--:-- --:--:-- 5746",
"stderr_lines": [
" % Total % Received % Xferd Average Speed Time Time Time Current",
" Dload Upload Total Spent Left Speed",
"",
" 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0",
"100 362 100 162 100 200 2571 3174 --:--:-- --:--:-- --:--:-- 5746"
],
"stdout": "{\"fileName\": \"test_config_1.txt\", \"path\": \"/rgnet/rxg_gateways\", \"bytes\": \"5\", \"mimeType\": \"application/octet-stream\", \"modified\": \"Fri Oct 13 02:43:30 UTC 2023\"}",
"stdout_lines": [
"{\"fileName\": \"test_config_1.txt\", \"path\": \"/rgnet/rxg_gateways\", \"bytes\": \"5\", \"mimeType\": \"application/octet-stream\", \"modified\": \"Fri Oct 13 02:43:30 UTC 2023\"}"
]
}
}
Now I have to write a task based on the fields present in the stdout in the response we have to parse stdout whether in stdout are present then it should print as success and if fields are missing then it should print the response as failure.