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"
    },
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
Sandeep C H
  • 11
  • 1
  • 2

3 Answers3

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  
NoNoNo
  • 1,963
  • 14
  • 20
  • 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 .. – Sandeep C H Apr 23 '19 at 10:59
  • TASK [debug] *********************************************************************************************************************************************************** ok: [localhost] => { "msg.json.value": "VARIABLE IS NOT DEFINED!" } – Sandeep C H Apr 23 '19 at 11:01
  • Try with - debug: var=msg.json.0.value or - debug: var=msg.json – NoNoNo Apr 23 '19 at 12:28
  • None of the above are working .... :( – Sandeep C H Apr 23 '19 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" } ] } – Sandeep C H Apr 24 '19 at 01: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
SunLynx
  • 1
  • 1
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" }

Sandeep C H
  • 11
  • 1
  • 2