How to update json fields using ansible update_fact module?

Here’s my playbook snippet:

- name: Get switch configuration
  uri:
    url: https://{{ ansible_host }}/api/v1/sites/{{ site_id }}/devices/{{ switch }}
    method: GET
    return_content: yes
    headers:
      Content-Type: "application/json"
      Authorization: "Token {{ mist_token }}"
    validate_certs: no
  ignore_errors: yes
  register: switch_configuration_response

- name: print switch_configuration_response
  debug:
    var: switch_configuration_response

- name: Parse JSON response
  set_fact:
    switch_configuration: "{{ switch_configuration_response.json }}"

- name: Define the target description
  set_fact:
    target_description: "INET_{{ link }}"

- name: Find the port key with the specified description
  set_fact:
    interface_name: "{{ item.key }}"
  loop: "{{ switch_configuration.port_config | dict2items }}"
  when: item.value.description == target_description

- name: print interface_name
  debug:
    var: interface_name

- name: Update the fact
  ansible.utils.update_fact:
    updates:
      - path: switch_configuration.port_config.{{ interface_name }}.usage
        value: disabled
  register: updated_switch_configuration

- name: print switch_configuration
  debug:
    var: switch_configuration

- name: print switch_configuration
  debug:
    var: updated_switch_configuration

Pay atention on this block:

- name: Update the fact
  ansible.utils.update_fact:
    updates:
      - path: switch_configuration.port_config.{{ interface_name }}.usage
        value: disabled
  register: updated_switch_configuration

- name: print switch_configuration
  debug:
    var: switch_configuration

- name: print updated switch_configuration
  debug:
    var: updated_switch_configuration 

When I run the playbook I expect that only the specific “usage” field is updated and the rest of the json remains untouched, but instead, it is creating a new key “switch_configuration” and putting all the values inside of it, as a redundance.

Output snippet:

TASK [print switch_configuration] **********************************************
ok: [JUNIPER_MIST] => {
    "switch_configuration": {
        "additional_config_cmds": [
            ""
        ],
        "bgp_config": null,
        "changed": true,
        "created_time": 1706718685,
        "deviceprofile_id": null,
        "disable_auto_config": false,
        "evpn_scope": null,
        "evpntopo_id": null,
        "failed": false,
        "hw_rev": "D",
        "id": "00000000-0000-0000-1000-bc0ffef85364",
        "ip_config": {
            "network": "default",
            "type": "dhcp"
        },
        "mac": "bc0ffef85364",
        "managed": true,
        "map_id": null,
        "model": "EX2300-24P",
        "modified_time": 1720131177,
        "name": "SW-MAG036-CORE1-TESTE2",
        "networks": {},
        "notes": "TESTE2",
        "oob_ip_config": {
            "type": "dhcp",
            "use_mgmt_vrf": false
        },
        "org_id": "5d568cec-dcd9-4fe9-ad1a-65c93640f9ad",
        "port_config": {
            "ge-0/0/0": {
                "critical": false,
                "description": "INET_EBT",
                "dynamic_usage": null,
                "no_local_overwrite": true,
                "usage": "vlan_52"
            },
            "ge-0/0/1": {
                "critical": false,
                "description": "INET_ALGAR",
                "dynamic_usage": null,
                "no_local_overwrite": true,
                "usage": "vlan_51"
            }
        },
        "port_usages": {},
        "role": "",
        "routing_policies": {},
        "serial": "JY4823370892",
        "site_id": "29ca1e1c-8958-4159-9568-f5070be1239a",
        "st_ip_base": "",
        "switch_config": {},
        "tag_id": 3452277,
        "tag_uuid": "5d568cec-dcd9-4fe9-ad1a-65c93640f9ad",
        "type": "switch"
    }
}

TASK [print updated switch_configuration] **********************************************
ok: [JUNIPER_MIST] => {
    "updated_switch_configuration": {
        "changed": true,
        "failed": false,
        "switch_configuration": {
            "additional_config_cmds": [
                ""
            ],
            "bgp_config": null,
            "changed": true,
            "created_time": 1706718685,
            "deviceprofile_id": null,
            "disable_auto_config": false,
            "evpn_scope": null,
            "evpntopo_id": null,
            "failed": false,
            "hw_rev": "D",
            "id": "00000000-0000-0000-1000-bc0ffef85364",
            "ip_config": {
                "network": "default",
                "type": "dhcp"
            },
            "mac": "bc0ffef85364",
            "managed": true,
            "map_id": null,
            "model": "EX2300-24P",
            "modified_time": 1720131177,
            "name": "SW-MAG036-CORE1-TESTE2",
            "networks": {},
            "notes": "TESTE2",
            "oob_ip_config": {
                "type": "dhcp",
                "use_mgmt_vrf": false
            },
            "org_id": "5d568cec-dcd9-4fe9-ad1a-65c93640f9ad",
            "port_config": {
                "ge-0/0/0": {
                    "critical": false,
                    "description": "INET_EBT",
                    "dynamic_usage": null,
                    "no_local_overwrite": true,
                    "usage": "vlan_52"
                },
                "ge-0/0/1": {
                    "critical": false,
                    "description": "INET_ALGAR",
                    "dynamic_usage": null,
                    "no_local_overwrite": true,
                    "usage": "disabled"
                }
            },
            "port_usages": {},
            "role": "",
            "routing_policies": {},
            "serial": "JY4823370892",
            "site_id": "29ca1e1c-8958-4159-9568-f5070be1239a",
            "st_ip_base": "",
            "switch_config": {},
            "tag_id": 3452277,
            "tag_uuid": "5d568cec-dcd9-4fe9-ad1a-65c93640f9ad",
            "type": "switch"
        }
    }
}

Pay attention on the new key “switch_configuration” created inside updated_switch_configuration. Any guesses on why is that happening?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật