# Formatting registered output

**URL:** <https://forum.ansible.com/t/formatting-registered-output/33390>\
**Category:** Ansible Project\
**Created:** [July 14, 2020, 7:29am UTC](https://forum.ansible.com/t/formatting-registered-output/33390 "2020-07-14T07:29:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albert\_Short](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Albert\_Short](https://forum.ansible.com/u/Albert_Short)\
**Post date:** [July 14, 2020, 7:29am UTC](https://forum.ansible.com/t/formatting-registered-output/33390/1 "2020-07-14T07:29:00Z")

</div>

All,

hope someone can assist here as i seem to be going in circles & not getting anywhere fast.

I am trying to map ACI VRFs to their associated parent tenant.  
The modules I am using with some basic Jinja2 filters allow me to map tenant–\>vrf but I now need to swap the order, to map vrf–\>tenant  
The idea is that once I have this mapping, a requester will on;ly need to provide the VRF id & I will map it to the correct tenant.

Here is what i have created so far with the output I have generated.

`

---

<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:** [July 14, 2020, 9:03am UTC](https://forum.ansible.com/t/formatting-registered-output/33390/2 "2020-07-14T09:03:28Z")

</div>

This task should create the dictionary

&nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_dict: "{{ my\_dict|default({})|combine({my\_key: my\_val}) }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ vrf\_query.current|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map(attribute='fvCtx.attributes.dn')|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map('replace', 'uni/tn-', '')|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map('replace', 'ctx-', '')|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_regex: '^(.\*)\/(.\*)$'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_regex\_key: '\2'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_regex\_val: '\1'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_key: "{{ item|regex\_replace(my\_regex, my\_regex\_key) }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_val: "{{ item|regex\_replace(my\_regex, my\_regex\_val) }}"

---

<div class="post-metadata">

**Author:** ![Albert\_Short](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Albert\_Short](https://forum.ansible.com/u/Albert_Short)\
**Post date:** [July 14, 2020, 9:14am UTC](https://forum.ansible.com/t/formatting-registered-output/33390/3 "2020-07-14T09:14:06Z")

</div>

Vladimir,

thanks for that fast response, it worked a wonder getting the info into the right format, thanks, now to move on to using it.

---

<div class="post-metadata">

**Author:** ![Albert\_Short](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Albert\_Short](https://forum.ansible.com/u/Albert_Short)\
**Post date:** [July 20, 2020, 3:28pm UTC](https://forum.ansible.com/t/formatting-registered-output/33390/4 "2020-07-20T15:28:39Z")

</div>

Vladimir,

finally got some time to look at this again & I have the following questions:

The fix you provided works by giving me the output, however I am having trouble getting to use it.  
First the output looks as follows:

`

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Monday 20 July 2020 16:14:05 +0100 (0:00:00.305) 0:00:01.452 \*\*\*\*\*\*\*\*\*\*\*  
ok: [############] =\>  
msg:  
changed: false  
msg: All items completed  
results:

- ansible\_facts:  
my\_dict:  
oob: mgmt  
ansible\_loop\_var: item  
changed: false  
failed: false  
item: mgmt/oob
- ansible\_facts:  
my\_dict:  
inb: mgmt  
oob: mgmt  
ansible\_loop\_var: item  
changed: false  
failed: false  
item: mgmt/inb
- ansible\_facts:  
my\_dict:  
ave-ctrl: infra  
inb: mgmt  
oob: mgmt  
ansible\_loop\_var: item  
changed: false  
failed: false  
item: infra/ave-ctrl
- ansible\_facts:  
my\_dict:  
ave-ctrl: infra  
default: common  
inb: mgmt  
oob: mgmt  
ansible\_loop\_var: item  
changed: false  
failed: false  
item: common/default
- ansible\_facts:  
my\_dict:  
ave-ctrl: infra  
default: common  
inb: mgmt  
oob: mgmt  
overlay-1: infra  
ansible\_loop\_var: item  
changed: false  
failed: false  
item: infra/overlay-1
- ansible\_facts:  
my\_dict:  
ave-ctrl: infra  
copy: common  
default: common  
inb: mgmt  
oob: mgmt  
overlay-1: infra  
ansible\_loop\_var: item  
changed: false  
failed: false  
item: common/copy
- ansible\_facts:  
my\_dict:  
ave-ctrl: infra  
copy: common  
default: common  
inb: mgmt  
oob: mgmt  
overlay-1: infra  
v11-aci: tn-shared  
vrf\_DEFAULT: tn\_NBK101  
ansible\_loop\_var: item  
changed: false  
failed: false  
item: tn\_NBK101/vrf\_DEFAULT
- ansible\_facts:  
my\_dict:  
ave-ctrl: infra  
copy: common  
default: common  
inb: mgmt  
oob: mgmt  
overlay-1: infra  
v13-aci: tn-prod-trusted  
vrf\_DEFAULT: tn\_NBK101  
ansible\_loop\_var: item  
changed: false  
failed: false  
item: tn-prod-trusted/v13-aci
- ansible\_facts:  
my\_dict:  
ave-ctrl: infra  
copy: common  
default: common  
inb: mgmt  
oob: mgmt  
overlay-1: infra  
v13-aci: tn-prod-trusted  
vrf\_DEFAULT: tn\_NBK101  
vrf\_UCSD: tn\_UCSD  
ansible\_loop\_var: item  
changed: false  
failed: false  
item: tn\_UCSD/vrf\_UCSD  
…

`

How do I manage to read just the last my\_dict output & use that for my next task in another role?  
I can get the output format correct to display just what I am looking for in my variable request.

`

- set\_fact:  
my\_dict: “{{ my\_dict|default({})|combine({my\_key: my\_val}) }}”  
loop: “{{ vrf\_query.current|  
map(attribute=‘fvCtx.attributes.dn’)|  
map(‘replace’, ‘uni/tn-’, ‘’)|  
map(‘replace’, ‘ctx-’, ‘’)|  
list  
}}”  
vars:  
my\_regex: ‘^(._)/(._)$’  
my\_regex\_key: ‘\2’  
my\_regex\_val: ‘\1’  
my\_key: “{{ item|regex\_replace(my\_regex, my\_regex\_key) }}”  
my\_val: “{{ item|regex\_replace(my\_regex, my\_regex\_val) }}”  
register: set\_fact\_output

- debug:  
msg: “{{set\_fact\_output.results}}”

`

I get the above results, but how can i move further down into the output to to get just the result for ‘v13-aci’ from my\_dict???

Again, any help would be greatly appreciated.

Regards
