I need help in with getting my play-book to parse data that is coming back from Ansible URI Response using "ansible.builtin.uri" module, trying to parse data json saved as var=result. But I keep seeing the following message, saying variable is not defined ! 'dict object has no attribute 'json'. The play-book come back with no syntax error nor any failures just this message below.
"result.json.data": "VARIABLE IS NOT DEFINED!: 'dict object' has no attribute 'json'"
- name: list details
ansible.builtin.uri:
url: "{{ kie_server_server }}{{ kie_server_port }}{{ kie_server_endpoint }}"
user: "{{ kieserver_user }}"
password: "{{ kieserver_password }}"
method: GET
validate_certs: false
status_code: 200
timeout: 30
register: result
- name: debug
ansible.builtin.debug:
var: result.json.data
// ------------------------------------------------------------------------
$ python3 --version
Python 3.6.8
$ ansible --version
ansible [core 2.13.3]
config file = /users/admin/ansible.cfg
configured module search path = ['/users/admin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.9/site-packages/ansible
ansible collection location = /users/admin/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.9.13 (main, Nov 9 2022, 13:16:24) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)]
jinja version = 3.1.2
libyaml = True
$
// ------------------------------------------------------------------------
$ ansible-playbook uricall.yml -l
reqres.in/api/users?page=2 -vvv
ansible-playbook [core 2.13.3]
config file = /users/admin/ansible.cfg
configured module search path = ['/users/admin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.9/site-packages/ansible
ansible collection location = /users/admin/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible-playbook
python version = 3.9.13 (main, Nov 9 2022, 13:16:24) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)]
jinja version = 3.1.2
libyaml = True
Using /users/admin/ansible.cfg as config file
host_list declined parsing /users/admin/hosts as it did not pass its verify_file() method
script declined parsing /users/admin/hosts as it did not pass its verify_file() method
auto declined parsing /users/admin/hosts as it did not pass its verify_file() method
Parsed /users/admin/hosts inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: uricall.yml *************************************************************************************************************************************************
1 plays in uricall.yml
PLAY [Validate KIE Server deployment] *********************************************************************************************************************************
META: ran handlers
TASK [list details] ***************************************************************************************************************************************************
task path: /users/admin/uricall.yml:15
<
reqres.in/api/users?page=2> ESTABLISH SSH CONNECTION FOR USER: None
<
reqres.in/api/users?page=2> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/users/admin/.ansible/cp/2abdb2e15a"'
reqres.in/api/users?page=2 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<
reqres.in/api/users?page=2> (0, b'/users/admin\n', b'')
<
reqres.in/api/users?page=2> ESTABLISH SSH CONNECTION FOR USER: None
<
reqres.in/api/users?page=2> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/users/admin/.ansible/cp/2abdb2e15a"'
reqres.in/api/users?page=2 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /users/admin/.ansible/tmp `"&& mkdir "` echo /users/admin/.ansible/tmp/ansible-tmp-1676942607.0676842-2055362-84558986433951 `" && echo ansible-tmp-1676942607.0676842-2055362-84558986433951="` echo /users/admin/.ansible/tmp/ansible-tmp-1676942607.0676842-2055362-84558986433951 `" ) && sleep 0'"'"''
<
reqres.in/api/users?page=2> (0, b'ansible-tmp-1676942607.0676842-2055362-84558986433951=/users/admin/.ansible/tmp/ansible-tmp-1676942607.0676842-2055362-84558986433951\n', b'')
Using module file /usr/lib/python3.9/site-packages/ansible/modules/uri.py
<
reqres.in/api/users?page=2> PUT /users/admin/.ansible/tmp/ansible-local-2055349bkonkdfj/tmpy1xvsbm3 TO /users/admin/.ansible/tmp/ansible-tmp-1676942607.0676842-2055362-84558986433951/AnsiballZ_uri.py
<
reqres.in/api/users?page=2> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/users/admin/.ansible/cp/2abdb2e15a"' '[
reqres.in/api/users?page=2]'
<
reqres.in/api/users?page=2> (0, b'sftp> put /users/admin/.ansible/tmp/ansible-local-2055349bkonkdfj/tmpy1xvsbm3 /users/admin/.ansible/tmp/ansible-tmp-1676942607.0676842-2055362-84558986433951/AnsiballZ_uri.py\n', b'')
<
reqres.in/api/users?page=2> ESTABLISH SSH CONNECTION FOR USER: None
<
reqres.in/api/users?page=2> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/users/admin/.ansible/cp/2abdb2e15a"'
reqres.in/api/users?page=2 '/bin/sh -c '"'"'chmod u+x /users/admin/.ansible/tmp/ansible-tmp-1676942607.0676842-2055362-84558986433951/ /users/admin/.ansible/tmp/ansible-tmp-1676942607.0676842-2055362-84558986433951/AnsiballZ_uri.py && sleep 0'"'"''
<
reqres.in/api/users?page=2> (0, b'', b'')
<
reqres.in/api/users?page=2> ESTABLISH SSH CONNECTION FOR USER: None
<
reqres.in/api/users?page=2> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/users/admin/.ansible/cp/2abdb2e15a"' -tt
reqres.in/api/users?page=2 '/bin/sh -c '"'"'/opt/bin/python /users/admin/.ansible/tmp/ansible-tmp-1676942607.0676842-2055362-84558986433951/AnsiballZ_uri.py && sleep 0'"'"''
<
reqres.in/api/users?page=2> (0, b'\r\n{"status": 200, "content_length": "3529", "cookies": {"JSESSIONID": "LLNxkYsDklms77MV4ofo8r1d6yUCuu-Krc4iR_aaz5jD3_EDIl8c!1154788022"}, "date": "Tue, 21 Feb 2023 01:23:29 GMT", "set_cookie": "JSESSIONID=LLNxkYsDklms77MV4ofo8r1d6yUCuu-Krc4iR_aaz5jD3_EDIl8c!1154788022; path=/; HttpOnly", "url": "
http://reqres.in/api/users?page=2:13421/kie-server/services/rest/server/containers", "changed": false, "elapsed": 0, "invocation": {"module_args": {"force": false, "remote_src": false, "status_code": [200], "owner": null, "body_format": "raw", "client_key": null, "group": null, "use_gssapi": false, "unix_socket": null, "unsafe_writes": false, "serole": null, "setype": null, "follow_redirects": "safe", "unredirected_headers": [], "return_content": false, "method": "GET", "mode": null, "body": null, "timeout": 30, "src": null, "dest": null, "selevel": null, "force_basic_auth": false, "removes": null, "http_agent": "ansible-httpget", "user": "user", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "use_proxy": true, "url_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "url": "
http://reqres.in/api/users?page=2:13421/kie-server/services/rest/server/containers", "seuser": null, "client_cert": null, "creates": null, "headers": {}, "ca_path": null, "url_username": "user", "attributes": null, "validate_certs": false}}, "connection": "close", "content_type": "application/xml", "msg": "OK (3529 bytes)", "redirected": false, "cookies_string": "JSESSIONID=LLNxkYsDklms77MV4ofo8r1d6yUCuu-Krc4iR_aaz5jD3_EDIl8c!1154788022"}\r\n', b'Shared connection to
reqres.in/api/users?page=2 closed.\r\n')
<
reqres.in/api/users?page=2> ESTABLISH SSH CONNECTION FOR USER: None
<
reqres.in/api/users?page=2> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/users/admin/.ansible/cp/2abdb2e15a"'
reqres.in/api/users?page=2 '/bin/sh -c '"'"'rm -f -r /users/admin/.ansible/tmp/ansible-tmp-1676942607.0676842-2055362-84558986433951/ > /dev/null 2>&1 && sleep 0'"'"''
<
reqres.in/api/users?page=2> (0, b'', b'')
ok: [
reqres.in/api/users?page=2] => {
"content_length": "3529",
"content_type": "application/xml",
"cookies": {
"JSESSIONID": "LLNxkYsDklms77MV4ofo8r1agawergad6yUCuu-Krc4iR_aaz5jD3_EDIl8c!1154788022"
},
"cookies_string": "JSESSIONID=LLNxkYsgswDklms77MV4ofqo8r1hd6yUCuu-Krc4iR_aaaz5jD3_EDIl8c!1154788022",
"date": "Tue, 21 Feb 2023 01:23:29 GMT",
"elapsed": 0,
"invocation": {
"module_args": {
"attributes": null,
"body": null,
"body_format": "raw",
"ca_path": null,
"client_cert": null,
"client_key": null,
"creates": null,
"dest": null,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {},
"http_agent": "ansible-httpget",
"method": "GET",
"mode": null,
"owner": null,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"remote_src": false,
"removes": null,
"return_content": false,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 30,
"unix_socket": null,
"unredirected_headers": [],
"unsafe_writes": false,
"url": "
http://reqres.in/api/users?page=2:13421/kie-server/services/rest/server/containers",
"url_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"url_username": "user",
"use_gssapi": false,
"use_proxy": true,
"user": "user",
"validate_certs": false
}
},
"msg": "OK (3529 bytes)",
"redirected": false,
"set_cookie": "JSESSIONID=LLNxkYsDklms77MV4ofo8r1d6yUCuu-Krc4iR_aaz5jD3_EDIl8c!1154788022; path=/; HttpOnly",
"status": 200,
"url": "
http://reqres.in/api/users?page=2:13421/kie-server/services/rest/server/containers"
}
TASK [debug] **********************************************************************************************************************************************************
task path: /users/admin/uricall.yml:26
ok: [
reqres.in/api/users?page=2] => {
"result.json.data": "VARIABLE IS NOT DEFINED!: 'dict object' has no attribute 'json'"
}
META: ran handlers
META: ran handlers
PLAY RECAP ************************************************************************************************************************************************************
reqres.in/api/users?page=2 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0