我正在从瞻博网络设备中提取事实并将该信息推送到 NetBox。
下面是我的剧本,基本上 set_fact 给了我最后一个结果,然后 netbox play 将相同的结果发送到我的所有接口,这不是我想要的。
- name: SETTING INT TYPE VIRTUAL
set_fact:
interfacetype: "Virtual"
loop: "{{ansible_network_resources.interfaces}}"
when: item.name == "irb" or
item.name == "lo0"
- name: SETTING INT TYPE 1GE
set_fact:
interfacetype: "1000BASE-T (1GE)"
loop: "{{ansible_network_resources.interfaces}}"
when: item.name | regex_search('(ge-)')
register: inter1
- name: SETTING INT TYPE 40GE
set_fact:
interfacetype: "QSFP+ (40GE)"
loop: "{{ansible_network_resources.interfaces}}"
when: item.name | regex_search('(et-)') and
ansible_net_model | regex_search('^ex[2-4][2346]00|qfx5100$')
- name: CREATE DEVICE INTERFACES
netbox_device_interface:
netbox_url: https://netbox.something.org
netbox_token: 99999999999999999999999999999999999
data:
device: "{{ ansible_net_hostname }}"
name: "{{ item.name }}"
description: "{{ item.description|default('') }}"
enabled: "{{ item.enabled }}"
mtu: "{{ item.mtu|default('') }}"
type: "{{ interfacetype }}"
state: present
loop: "{{ansible_network_resources.interfaces}}"
delegate_to: localhost
我认为基于上述内容,以下内容更有意义。我想我需要在列表中组合每个部分,每个部分都有一个指向 ge 的字典 - 一个类似于intertype:"1000BASE-T (1GE)"的新项目
这样我就可以在最后一场比赛中使用该词典列表。
这就是我得到的:
ok: [device1.something.org] => {
"ansible_network_resources.interfaces": [
{
"enabled": true,
"mtu": 9216,
"name": "ge-0/0/0"
},
{
"enabled": false,
"mtu": 9216,
"name": "ge-0/0/1"
},
{
"enabled": false,
"mtu": 9216,
"name": "ge-0/0/2"
},
{
"enabled": false,
"mtu": 9216,
"name": "ge-0/0/3"
},
{
"enabled": false,
"mtu": 9216,
"name": "ge-0/0/4"
},
{
"description": "agaga2",
"enabled": true,
"mtu": 9216,
"name": "et-0/1/0"
},
{
"enabled": false,
"mtu": 9216,
"name": "et-0/1/1"
},
{
"enabled": true,
"mtu": 9216,
"name": "xe-0/2/0"
},
{
"enabled": false,
"mtu": 9216,
"name": "xe-0/2/1"
},
{
"enabled": false,
"mtu": 9216,
"name": "xe-0/2/2"
},
{
"description": "blabla1",
"enabled": true,
"mtu": 9216,
"name": "xe-0/2/3"
},
{
"enabled": true,
"name": "irb"
},
{
"enabled": true,
"name": "lo0"
}
]
}
我可以在里面添加一个新字典,结果如下:
{
"intertype":"Virtual"
"enabled": true,
"name": "lo0"
}
{
"intertype":"QSFP+ (40GE)"
"enabled": false,
"mtu": 9216,
"name": "et-0/2/2"
},
{
"intertype":"1000BASE-T (1GE)"
"enabled": false,
"mtu": 9216,
"name": "ge-0/0/1"
},