# KEY: VALUE iterations

**URL:** <https://forum.ansible.com/t/key-value-iterations/32217>\
**Category:** Ansible Project\
**Created:** [February 13, 2020, 2:02am UTC](https://forum.ansible.com/t/key-value-iterations/32217 "2020-02-13T02:02:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [February 13, 2020, 2:02am UTC](https://forum.ansible.com/t/key-value-iterations/32217/1 "2020-02-13T02:02:20Z")

</div>

Hi,  
What is the best way to loop the below KEY : VALUE ?

main.yml

var\_files:

- /home/ansible/sqlvar.yml

- name: Script  
oracle\_sql:  
sql: {{Value}}  
environment: “{{oracle\_env}}”  
register: query\_result  
connection: local

- name: Runs statements  
command: $ORACLE\_HOME/sqlplus -s {{user}}/{{password}}@{{sname}} @/home/ansible/Playbooks/{{sname}}/sql/{{Key}}\_revoke.sql  
environment: “{{oracle\_env}}”  
register: sqloutput  
connection: local

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [February 13, 2020, 3:38am UTC](https://forum.ansible.com/t/key-value-iterations/32217/2 "2020-02-13T03:38:00Z")

</div>

Try this

&nbsp;&nbsp;&nbsp;&nbsp;- include\_vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file: /home/ansible/sqlvar.yml  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: scripts  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ item.key }}: {{ item.value }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ scripts|dict2items }}"

HTH,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [February 13, 2020, 3:52am UTC](https://forum.ansible.com/t/key-value-iterations/32217/3 "2020-02-13T03:52:31Z")

</div>

You helped me Vlado. Thanks again. This works very well.

How will get the value of item.key and item.value to variable

sqlqry = “{{ item.key }}”  
sqlid = “{{ item.value }}”

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [February 13, 2020, 3:55am UTC](https://forum.ansible.com/t/key-value-iterations/32217/4 "2020-02-13T03:55:10Z")

</div>

Basically I want to read sqlvar.yml, pass the “select username from dba\_users;” to SQLID and “Script1” to SQLQRY one by one.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [February 13, 2020, 4:22am UTC](https://forum.ansible.com/t/key-value-iterations/32217/5 "2020-02-13T04:22:31Z")

</div>

Declare the vars in the scope of the task. For example

&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ sqlqry }}: {{ sqlid }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlqry: "{{ item.key }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlid: "{{ item.value }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ scripts|dict2items }}"

HTH,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [February 13, 2020, 1:57pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/6 "2020-02-13T13:57:39Z")

</div>

Thanks again Vlado. I am struggling with the basics here…

This is my block

- include\_vars:  
file: /home/ansible/Playbooks/Compliance1.yml  
name: scripts
- debug:  
msg: “{{ sqlqry }}: {{ sqlid }}”  
vars:  
sqlqry: “{{ item.key }}”  
sqlid: “{{ item.value }}”  
loop: “{{ scripts|dict2items }}”

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [February 13, 2020, 3:24pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/7 "2020-02-13T15:24:16Z")

</div>

> &nbsp;&nbsp;&nbsp;&nbsp;- include\_vars:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file: /home/ansible/Playbooks/Compliance1.yml  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: scripts  
> &nbsp;&nbsp;&nbsp;&nbsp;- debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ sqlqry }}: {{ sqlid }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlqry: "{{ item.key }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlid: "{{ item.value }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ scripts|dict2items }}"  
> [...]  
> The Complaince1.yml has the below
> 
> Script1: select username from dba\_users;  
> Script2: select name from v$profile;  
> [...]  
> &nbsp;&nbsp;&nbsp;&nbsp;"msg": "Script1: select username from dba\_users;"  
> &nbsp;&nbsp;&nbsp;&nbsp;"msg": "Script2: select name from v$profile;"
> 
> My problem is, I don't know how to get the key (like "Script1") and value  
> (like "select username from dba\_users;") to another block as
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- name: Script will revoke  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oracle\_sql:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username: "{{user}}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password: "{{password}}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;service\_name: "{{sname}}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port: "{{prt}}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlId: "{{hostnme}}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sql: "{{sqlqry}}'

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlqry: "{{ item.key }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlid: "{{ item.value }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ scripts|dict2items }}"

Simply append "vars" and "loop".

But I think the above task "oracle\_sql" won't work because of attribute  
"sql". The documentation says "sql: The sql you want to execute" but  
"item.key" is the label of the script. See  
[https://github.com/oravirt/ansible-oracle-modules/blob/master/oracle\_sql](https://github.com/oravirt/ansible-oracle-modules/blob/master/oracle_sql)

Instead, "item.value" is the SQL you want to execute. Correct syntax is  
(substitution is not necessary)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Script will revoke  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oracle\_sql:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username: "{{ user }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password: "{{ password }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;service\_name: "{{ sname }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port: "{{ prt }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlId: "{{ hostnme }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sql: "{{ item.value }}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ scripts|dict2items }}"

> &nbsp;&nbsp;&nbsp;&nbsp;- name: Runs the revoke statements and spool out.  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: $ORACLE\_HOME/sqlplus -s {{user}}/{{password}}@{{sname}}  
> @/home/ansible/Playbooks/{{sname}}/sql/{{sqlid}}\_revoke.sql  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;environment: "{{oracle\_env}}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: sqloutput  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection: local

dtto. Change "sqlid" to "item.key"

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Runs the revoke statements and spool out.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: $ORACLE\_HOME/sqlplus -s {{user}}/{{password}}@{{sname}}  
&nbsp;&nbsp;@/home/ansible/Playbooks/{{sname}}/sql/{{ item.key }}\_revoke.sql  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;environment: "{{oracle\_env}}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: sqloutput  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection: local  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ scripts|dict2items }}"

HTH,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [February 13, 2020, 4:32pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/8 "2020-02-13T16:32:08Z")

</div>

Hello Vlado,  
sql works fine actually. No issues with that. I am getting the query results. Here is the result

“msg”: {  
“changed”: false,  
“msg”: “All items completed”,  
“results”: [  
{  
“ansible\_facts”: {  
“discovered\_interpreter\_python”: “/usr/bin/python”  
},  
“ansible\_loop\_var”: “item”,  
“changed”: false,  
“failed”: false,  
“invocation”: {  
“module\_args”: {  
“host”: “[tstdb.cdst2lsongoi.us-east-1.rds.amazonaws.com](http://tstdb.cdst2lsongoi.us-east-1.rds.amazonaws.com)”,  
“hostname”: “[tstdb.cdst2lsongoi.us-east-1.rds.amazonaws.com](http://tstdb.cdst2lsongoi.us-east-1.rds.amazonaws.com)”,  
“mode”: “normal”,  
“password”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“port”: “1521”,  
“script”: null,  
“service\_name”: “tstdb”,  
“sql”: “select name from v$database;”,  
“user”: “DBUSER”,  
“username”: “DBAUSER”  
}  
},  
“item”: {  
“key”: “Script1”,  
“value”: “select name from v$database;”  
},  
“msg”: [  
[  
“TSTDB”  
]  
]  
}

I have jinja template embedded in my play book, it captures the whole json

Thank you so much for your help !!!

- Anand

- name: Generate Revoke Statement  
copy:  
dest: /home/ansible/Playbooks/{{sname}}/sql/{{item.key}}\_revoke.sql  
content: |  
spool /home/ansible/Playbooks/{{sname}}/log/{{item.key}}.log  
{% for line in query\_result.msg |flatten %}  
{{ line }}  
{% endfor %}  
spool off;  
delegate\_to: localhost  
connection: local  
loop: “{{ scripts|dict2items }}”

How do I capture only the query result which is just the username ?

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [February 13, 2020, 5:16pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/9 "2020-02-13T17:16:59Z")

</div>

I don't understand what "the query result which is just the username" means.  
What result do you expect?

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [February 13, 2020, 5:25pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/10 "2020-02-13T17:25:16Z")

</div>

Sorry about that.

Here is what I get as the debug out when I run my loop. I need to parse the JSON and get the hightlighted value to my Jinja template.

“msg”: {  
“changed”: false,  
“msg”: “All items completed”,  
“results”: [  
{  
“ansible\_facts”: {  
“discovered\_interpreter\_python”: “/usr/bin/python”  
},  
“ansible\_loop\_var”: “item”,  
“changed”: false,  
“failed”: false,  
“invocation”: {  
“module\_args”: {  
“host”: “[tstdb.cds56fb9ngoi.us-east-1.rds.amazonaws.com](http://tstdb.cds56fb9ngoi.us-east-1.rds.amazonaws.com)”,  
“hostname”: “[tstdb.cdst2nb9ngoi.us-east-1.rds.amazonaws.com](http://tstdb.cdst2nb9ngoi.us-east-1.rds.amazonaws.com)”,  
“mode”: “normal”,  
“password”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“port”: “1521”,  
“script”: null,  
“service\_name”: “tstdb”,  
“sql”: “select name from v$database;”,  
“user”: “DBUSER”,  
“username”: “DBUSER”  
}  
},  
“item”: {  
“key”: “Script1”,  
“value”: “select name from v$database;”  
},  
“msg”: [  
[  
“LCKTSTDB”  
]  
]  
}

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [February 13, 2020, 5:34pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/11 "2020-02-13T17:34:13Z")

</div>

> Here is what I get as the debug out when I run my loop. I need to parse the  
> JSON and get the hightlighted value to my Jinja template.

&nbsp;&nbsp;I don't see anything highlighted. What am I missing?

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [February 13, 2020, 7:52pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/12 "2020-02-13T19:52:30Z")

</div>

Thanks again Vlado

I want to parse the json output and take the values

Here is the json debug output from the playbook I run,

TASK [Display the query results] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: "[tstdb.fdst3sb9ngoi.us-east-1.rds.amazonaws.com](http://tstdb.fdst3sb9ngoi.us-east-1.rds.amazonaws.com)] =\> {  
“msg”: {  
“ansible\_loop\_var”: “item”,  
“changed”: false,  
“failed”: false,  
“invocation”: {  
“module\_args”: {  
“host”: “[tstdb.fdst3sb9ngoi.us-east-1.rds.amazonaws.com](http://tstdb.fdst3sb9ngoi.us-east-1.rds.amazonaws.com)”,  
“hostname”: “[tstdb.fdst3sb9ngoi.us-east-1.rds.amazonaws.com](http://tstdb.fdst3sb9ngoi.us-east-1.rds.amazonaws.com)”,  
“mode”: “normal”,  
“password”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“port”: “1521”,  
“script”: null,  
“service\_name”: “tstdb”,  
“sql”: “select 'Revoke ’ || privilege || ’ on UTL\_FILE from ’ || grantee || ‘;’ from dba\_tab\_privs where table\_name=‘UTL\_FILE’ and grantee not like ‘APEX%’ and grantee != ‘CTXSYS’ and grantee != ‘DBSNMP’ order by grantee;”,  
“user”: “SYSDBA”,  
“username”: “SYSDBA”  
}  
},  
“item”: {  
“key”: “Script1”,  
“value”: “select 'Revoke ’ || privilege || ’ on UTL\_FILE from ’ || grantee || ‘;’ from dba\_tab\_privs where table\_name=‘UTL\_FILE’ and grantee not like ‘APEX%’ and grantee != ‘CTXSYS’ and grantee != ‘DBSNMP’ and grantee != ‘DMSYS’ and grantee != ‘EXFSYS’ and grantee != ‘MDSYS’ order by grantee;”  
},  
“msg”: [  
[  
“Revoke EXECUTE on UTL\_FILE from TESTDBA;”  
],  
[  
“Revoke EXECUTE on UTL\_FILE from TSTSCH;”  
]  
]  
}  
]  
}  
}

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [February 13, 2020, 9:27pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/13 "2020-02-13T21:27:48Z")

</div>

There is nothing to parse. The result is a dictionary with the attributes  
listed in "msg". Simply access the attributes of the dictionary to "take the  
values".

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [February 13, 2020, 9:33pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/14 "2020-02-13T21:33:32Z")

</div>

Thank you so very much Vlado

if I say

- name: Display the query results  
debug:  
msg: "{{query\_result.msg}}

I get the below

“msg”: “All items completed”

I couldn’t get the below, what ever I put in my debug statement. Is there is something I should do in order to get the below messages ? Thanks again for your help.

“msg”: [  
[  
“Revoke EXECUTE on UTL\_FILE from TESTDBA;”  
],  
[  
“Revoke EXECUTE on UTL\_FILE from TSTSCH;”  
]  
]

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [February 13, 2020, 10:07pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/15 "2020-02-13T22:07:55Z")

</div>

> - name: Display the query results  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{query\_result.msg}}
> 
> I get the below  
> &nbsp;&nbsp;"msg": "All items completed"
> 
> I couldn't get the below, what ever I put in my debug statement. Is there  
> is something I should do in order to get the below messages ? Thanks again  
> for your help.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"msg": [  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Revoke EXECUTE on UTL\_FILE from TESTDBA;"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;],  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Revoke EXECUTE on UTL\_FILE from TSTSCH;"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]

What you should do in order to get the above messages? Solve the mystery and  
find out how you get the "msg" below. Perhaps?

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [February 14, 2020, 12:31pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/16 "2020-02-14T12:31:03Z")

</div>

Thanks Vlado,  
I am new to Ansible. I tried "query\_result.results’ etc. But no luck. Will really appreciate and also will learn at the same time if you can help me crack the mystery.

Thanks for all your help.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 14, 2020, 12:51pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/17 "2020-02-14T12:51:27Z")

</div>

> Thanks Vlado,  
> I am new to Ansible. I tried "query\_result.results' etc. But no luck. Will really appreciate and also will learn at the  
> same time if you can help me crack the mystery.
> 
> Thanks for all your help.

Amand, you need to use the loop in the debug task as well:

- name: Display the query results  
&nbsp;&nbsp;debug:  
&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{query\_result.msg}}  
&nbsp;&nbsp;loop: "{{ scripts|dict2items }}"

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [February 14, 2020, 1:10pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/18 "2020-02-14T13:10:45Z")

</div>

Thanks Rache,  
This didn’t solve the issue. I need to read the content in the “msg” in “results” section

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 14, 2020, 1:27pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/19 "2020-02-14T13:27:28Z")

</div>

> Thanks Rache,  
> This didn't solve the issue. I need to read the content in the "msg" in "results" section

What's the output when you run it in a loop as suggested?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [February 14, 2020, 1:32pm UTC](https://forum.ansible.com/t/key-value-iterations/32217/20 "2020-02-14T13:32:34Z")

</div>

That was reading the first msg

“msg”: “All items completed”

We want to read the msg in results

“msg”: [  
[  
“Revoke EXECUTE on UTL\_FILE from TESTDBA;”  
],  
[  
“Revoke EXECUTE on UTL\_FILE from TSTSCH;”  
]  
]

[Next page](https://forum.ansible.com/t/key-value-iterations/32217.md?page=2)
