Formatting registered output

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.

`

This task should create the dictionary

    - 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) }}"

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.

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