I'm pulling the facts from Juniper devices and pushing that information to NetBox.
Below is my playbook, basically set_fact gives me the last result and then the netbox play sends the same result to all my interfaces, and that's not what I want.
- 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
I think the below makes more sense based on the above.
I think I need to combine inside the list, on each part that has a dictionary pointing to ge- a new item that will be like intertype:"1000BASE-T (1GE)"
That way I can use that list of dictionaries on the last play.
This is what I get:
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"
}
]
}
Can I add inside there a new dictionary so that the result is the following:
{
"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"
},
question from:
https://stackoverflow.com/questions/65930814/sec-fact-gives-me-the-last-match