# Help printing out key/value pair from a register?

**URL:** <https://forum.ansible.com/t/help-printing-out-key-value-pair-from-a-register/26665>\
**Category:** Ansible Project\
**Created:** [February 5, 2018, 4:10pm UTC](https://forum.ansible.com/t/help-printing-out-key-value-pair-from-a-register/26665 "2018-02-05T16:10:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [February 5, 2018, 4:10pm UTC](https://forum.ansible.com/t/help-printing-out-key-value-pair-from-a-register/26665/1 "2018-02-05T16:10:48Z")

</div>

I have a register with the following output of a query from the acl module.

`  
ok: [[server.domain.com](http://server.domain.com)] =\> {  
“acl\_query.results”: [  
{  
“\_ansible\_item\_result”: true,  
“\_ansible\_no\_log”: false,  
“changed”: false,  
“item”: [  
{  
“path”: “/local/py/virtualenvs/service\_mix/logs”  
},  
{  
“etype”: “other”,  
“permissions”: “rwx”  
}  
],  
“skip\_reason”: “Conditional result was False”,  
“skipped”: true  
},  
{  
“\_ansible\_item\_result”: true,  
“\_ansible\_no\_log”: false,  
“changed”: false,  
“item”: [  
{  
“path”: “/local/py/virtualenvs/service\_mix/tmp\_files”  
},  
{  
“etype”: “other”,  
“permissions”: “rwx”  
}  
],  
“skip\_reason”: “Conditional result was False”,  
“skipped”: true  
},  
{  
“\_ansible\_item\_result”: true,  
“\_ansible\_no\_log”: false,  
“\_ansible\_parsed”: true,  
“acl”: [  
“user::rwx”,  
“user:cva:rwx”,  
“user:scmauto:rwx”,  
“group::r-x”,  
“mask::rwx”,  
“other::r-x”,  
“default:user::rwx”,  
“default:user:cva:rwx”,  
“default:user:scmauto:rwx”,  
“default:group::r-x”,  
“default:mask::rwx”,  
“default:other::r-x”  
],  
“changed”: false,  
“failed”: false,  
“invocation”: {  
“module\_args”: {  
“default”: false,  
“entity”: “”,  
“entry”: null,  
“etype”: null,  
“follow”: true,  
“path”: “/local/httpd”,  
“permissions”: null,  
“recursive”: false,  
“state”: “query”,  
“use\_nfsv4\_acls”: false  
}  
},  
“item”: [  
{  
“path”: “/local/httpd”  
},  
{  
“entity”: “my\_user”,  
“etype”: “user”,  
“permissions”: “rwx”  
}  
],  
“msg”: “current acl”  
}  
]  
}

`

How can I write a debug module that will show me, for each item in results array, the path, entity, etype, and permissions values?

`

- debug: msg=“{{ acl\_query.results.??? }}”  
`

(Why am I so bad at this? LOL)

---

<div class="post-metadata">

**Author:** ![Claudia\_de\_Luna](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@Claudia\_de\_Luna](https://forum.ansible.com/u/Claudia_de_Luna)\
**Post date:** [February 6, 2018, 1:14am UTC](https://forum.ansible.com/t/help-printing-out-key-value-pair-from-a-register/26665/2 "2018-02-06T01:14:21Z")

</div>

Hi ZillaYT,

Its sometimes difficult to figure out how to get to specific values that are returned. Some times you have to “deconstruct” it.

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

Normally I register my output

register: facts\_output

and then I start drilling down. Looking at the data structure in something that helps you visualize it helps me. So this is a list of dictionaries and

- debug: var=facts\_output
- debug: var=facts\_output.ansible\_facts.ansible\_net\_version

Here is a longer version but if you figure out your data structure you don’t have to do this “trial and error” method.

# 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]

See [this email exchange](https://groups.google.com/forum/#!topic/ansible-project/Ul5D-gAzRrg) on a similar topic.

So you are going to want to see (assuming you save (register) your output into avariable called “output”:

- debug: var=output.acl\_query.results[‘2’].item[0].path

- debug: var=output.acl\_query.results[‘2’].item[1].entity

- debug: var=output.acl\_query.results[‘2’].item[1].etype

- debug: var=output.acl\_query.results[‘2’].item[1].permissions

..you get the idea

[![](https://us1.discourse-cdn.com/ansible/original/2X/f/fdf6e3fff2afb82509316e85d0914bbd2c6ccac9.png)](https://lh3.googleusercontent.com/-dQTvHSNp5-w/WnkBVO-H3yI/AAAAAAAAF18/-AtgGlEy9LAJ7Qna4-TGoycSJqtUe6MbgCLcBGAs/s1600/2018-02-05_17-06-19.png)
