需要在 Ansible 中使用相同的键合并 2 个字典

问题描述 投票:0回答:0

我的 Ansible 剧本中有 2 个字典(整数和接口),它们共享相同的键(接口名称),我想将它们合并到一个字典中。

ints 字典具有以下结构:

"ints": {
        "GigabitEthernet 1/1": {
            "bandwidth": 1000,
            "description": null,
            "duplex": "full",
            "ipv4": null,
            "lineprotocol": "up",
            "macaddress": "8c:47:be:64:8a:82",
            "mediatype": null,
            "mtu": 1554,
            "operstatus": "up",
            "type": "DellEth"
        }

接口具有以下结构:

 "interfaces": {
        "GigabitEthernet 1/1": {
            "lag": "",
            "mode": "Tagged",
            "tagged": [
                "1007"
            ],
            "untagged": "1641"
        }

我正在尝试合并它们:

 - name: Combine dictionaries
      set_fact:
        merged_dict: "{{ ints | combine(interfaces) }}"

    - debug:
        var: merged_dict

希望得到这个:

 "merged_dict": {
       "GigabitEthernet 1/1": {
             "bandwidth": 1000,
            "description": null,
            "duplex": "full",
            "ipv4": null,
            "lineprotocol": "up",
            "macaddress": "8c:47:be:64:8a:82",
            "mediatype": null,
            "mtu": 1554,
            "operstatus": "up",
            "type": "DellEth"
            "lag": "",
            "mode": "Tagged",
            "tagged": [
                "1007"
            ],
            "untagged": "1641"
        }

但是我只得到这个:

"merged_dict": {
       "GigabitEthernet 1/1": {
            "lag": "",
            "mode": "Tagged",
            "tagged": [
                "1007"
            ],
            "untagged": "1641"
        }

有更多经验的人可以指出我做错了什么吗?

非常感谢您,祝您有美好的一天

ansible
© www.soinside.com 2019 - 2024. All rights reserved.