Hi Surjeet,

It might help to understand if you think of your variable "version" as a 
dictionary of lists of dictionaries.  Think of it as a data structure that 
you need to decompose to understand.

If you take the output you get when you run your playbook and paste it into 
something like https://jsoneditoronline.org/ you can start to understand 
the structure and that will make it much easier to pick out the information 
you need.

for example:  I have a playbook that runs "show version" and "show inv"

once I save the output into a variable I called output (equivalent to your 
"version" variable) I can see that my output structure is a dictionary with 
three key value pairs:  {"changed": false, "msg": "all items completed", 
results: <this is a list of dictionaries with the first element [0] having 
data to do with show version and the second element [1] having data to do 
with show inv}

You can also see that results[0] has keys like item, stdout, stdout_lines 
(which is a list), changed, failed, etc..

If you decompose output.results[0].item you get the command that was run.

TASK [debug] 
********************************************************************************************************************************************************
ok: [arctic-3650] => {
    "output.results[0].item": "show version"
}


This is the part of my playbook where I try to decompose the data so you 
see me printing out various parts of the data structure.

      # save the command output in a variable called "output"
      register: output
      # print the contents of the variable "output" which is a dictionary 
of lists of dictionaries
    - debug: var=output
      # print the first command that was run
    - debug: var=output.results[0].item
      # print the command results with line feeds
    - debug: var=output.results[0].stdout_lines
      # print the list item #72 
    - debug: var=output.results[0].stdout_lines[0][72]

<snip>

TASK [debug] 
********************************************************************************************************************************************************
ok: [arctic-3650] => {
    "output.results[0].stdout_lines[0][72]": "*    1 28    WS-C3650-24TS   
   03.06.06E         cat3k_caa-universalk9 INSTALL"
}

Having said all of this because its key to be able to figure out what you 
get back from the playbook run, give the ios_facts module a try!




<https://lh3.googleusercontent.com/-rKkNzUTPlHg/WmTQutIoufI/AAAAAAAAF0Y/1XK1a-fp8YgaNcGoFGvSR27Wd7EEPFcaACLcBGAs/s1600/2018-01-21_09-37-14.png>
 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1666b615-3a1d-4b08-b476-80495cc2e395%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to