Adding a Fact to a dict for Cisco Interf.

I have the following that is not working.

`
vars:
cmdb: xkjsdflkjsjdl4d
cisco_ios:
interfaces:
gigabit1/0/1:
name: Gigabit1/0/1
status: up
gigabit1/0/2:
name: Gigabit1/0/2
status: down
tasks:

  • name: Test in loop
    include: test_loop_fact2.yml
    loop: “{{ cisco_ios.interfaces | dict2items }}”
  • debug:
    var: cisco_ios

test_loop_fact2**.yml:**

  • name: set fact
    set_fact:
    new_fact:
    interfaces:
    “{{ item.key }}”:

cmdbId: “{{ cmdb }}”

  • name: merge
    set_fact:
    cisco_ios: “{{ cisco_ios|combine(new_fact,recursive=True) }}”
    cacheable: true

`

I want to be able to insert cmdbId under cisco_ios.interfaces.gigabit1/0/1 and cisco_ios.interfaces.gigabit1/0/2 but I cannot figure out how to do this. With the above I get:

`
TASK [debug] ****************************************************************************************************************************************************************************
ok: [127.0.0.1] => {
“cisco_ios”: {
“interfaces”: {
“gigabit1/0/1”: {
“name”: “Gigabit1/0/1”,
“status”: “up”
},
“gigabit1/0/2”: {
“name”: “Gigabit1/0/2”,
“status”: “down”
},
“{{ item.key }}”: {
“cmdbId”: “xkjsdflkjsjdl4d”
}
}
}
}

`

I’ve tried removing the “{{ }}” and tried but get errors. How do I reference it.
I want to end up with

cisco_ios:
interfaces:
gigabit1/0/1:
name: Gigabit1/0/1
status: up
cmdbId: xxxxxx
gigabit1/0/2:
name: Gigabit1/0/2
status: down
cmdbId: xxxxxx

Is this probably what are you looking for?

    - set_fact:
        interfaces: "{{ interfaces|default({})|
                        combine({item.key: item.value|
                        combine({'cmdbId': cmdb})}) }}"
      loop: "{{ cisco_ios.interfaces|dict2items }}"
    - set_fact:
        cisco_ios: "{{ cisco_ios.interfaces|combine(interfaces) }}"

Cheers,

  -vlado

    - set_fact:
        cisco_ios: "{{ cisco_ios.interfaces|combine(interfaces) }}"

Errata:

     - set_fact:
         cisco_ios: "{{ cisco_ios|combine({'interfaces': interfaces}) }}"