1

From the Below output I need to see only "Value " information .. How to debug to get only Value information ??/

ok: [localhost] => { "msg": { "changed": false, "connection": "close", "content_length": "342", "content_type": "application/json", "cookies": {}, "cookies_string": "", "date": "Tue, 23 Apr 2019 07:44:55 GMT", "failed": false, "json": { "info": [ { "name": "networkDomainId", "value": "f173b777-d460-4050-9562-fc6b201415c3" } ], "message": "Request to Deploy Network Domain has been accepted. Please use appropriate Get or List API for status.", "operation": "DEPLOY_NETWORK_DOMAIN", "requestId": "eu_20190423T094455564+0200_1515ad61-58a7-4853-96fb-2b52d8eddd8a", "responseCode": "IN_PROGRESS" }, 
1
  • What is "o/p"? Which value do you want? Commented Apr 24, 2019 at 1:40

3 Answers 3

1

A task like the following should solve your problem:

- debug: var=msg.json.value 

Below an example using another task( I don't know which module have you used to produce the msg variabile reported in your question):

$ cat /tmp/tmp - hosts: localhost tasks: - command: uptime register: msg - debug: var=msg - debug: var=msg.cmd $ ansible-playbook /tmp/tmp PLAY [localhost] ***************************************************************************** TASK [Gathering Facts] *********************************************************************** ok: [localhost] TASK [command] ******************************************************************************* changed: [localhost] TASK [debug] ********************************************************************************* ok: [localhost] => { "msg": { "changed": true, "cmd": [ "uptime" ], "delta": "0:00:00.003576", "end": "2019-04-23 11:45:43.393217", "rc": 0, "start": "2019-04-23 11:45:43.389641", "stderr": "", "stderr_lines": [], "stdout": " 11:45:43 up 1:57, 1 user, load average: 0,33, 0,61, 0,83", "stdout_lines": [ " 11:45:43 up 1:57, 1 user, load average: 0,33, 0,61, 0,83" ] } } TASK [debug] ********************************************************************************* ok: [localhost] => { "msg.cmd": [ "uptime" ] } PLAY RECAP *********************************************************************************** localhost : ok=4 changed=1 unreachable=0 failed=0 
5
  • I am using uri module to run api call.. And above is the o/p I am getting and I need the Value to be passed to next module has a variable .. Commented Apr 23, 2019 at 10:59
  • TASK [debug] *********************************************************************************************************************************************************** ok: [localhost] => { "msg.json.value": "VARIABLE IS NOT DEFINED!" } Commented Apr 23, 2019 at 11:01
  • Try with - debug: var=msg.json.0.value or - debug: var=msg.json Commented Apr 23, 2019 at 12:28
  • None of the above are working .... :( Commented Apr 23, 2019 at 14:18
  • I am getting below o/p ... register: create - debug: msg: "{{ create.json.info }}" ok: [localhost] => { "msg": [ { "name": "networkDomainId", "value": "458ec357-df65-4c5e-b042-4d80cfbae7fd" } ] } Commented Apr 24, 2019 at 1:21
0
  1. You can take output in a file and grep for value.
 grep value <filename> 
  1. To debug ansible output use -vvv
 ansible-playbook abc.yml -vvv 
0

I got the answer with below line ..

register: create - debug:

 var: create.json.info.0.value 

ok: [localhost] => { "create.json.info.0.value": "b9cebba5-22d5-4689-b04e-3882f377f575" }

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.