0

I am currently using the netbox ansible module to pull interface information from Cisco devices into Netbox. So far I have managed to pull in the interfaces and basic information like their MAC addresses.

Is there a way that you can get the untagged and tagged VLANS on each port and push them into netbox too?

This is my current ansible playbook:

---
- name: "PLAY 1: ADD INTERFACES TO NETBOX AND CLEANUP TEMP"
  connection: network_cli
  hosts: platforms_ios
  tags: [ ios ]
  tasks:
    - name: "TASK 1: IOS >> GET IOS FACTS"
      ios_facts:
        gather_subset: "!config"
      when: "ansible_network_os == 'ios'"

    - name: "TASK 2: NETBOX >> ADD INTERFACES TO NETBOX"
      netbox.netbox.netbox_device_interface:
        netbox_url: "<netbox url>"
        netbox_token: "<netbox_token>"
        data:
          device: "{{ inventory_hostname }}"
          name: "{{ item.key }}"
          form_factor: "{{ item.key | get_interface_type }}"
          mac_address: "{{ item.value.macaddress | convert_mac_address }}"
        state: present
      with_dict:
        - "{{ ansible_facts['net_interfaces'] }}"
      loop_control:
        label: "{{ item.key }}"

netbox.netbox.netbox_device_interface has options for untagged_vlan: and tagged_vlans: in their documentation. I am unsure if this information can be provided from ansible however.

Nick Carlton
  • 35
  • 1
  • 4
  • I don't have (as most people here I guess) an IOS device to gather facts from and check. Meanwhile, from [documentation](https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_facts_module.html#parameter-gather_network_resources), it seems that `ios_facts` can gather info about vlans. – Zeitounator Jan 10 '21 at 22:47
  • In case your are looking for a way to see all possible facts returned by the module to check if you can find what your are looking for somewhere, you can print the following message with debug: `"{{ hostvars[inventory_hostname] | dict2items | selectattr('key', 'match', 'ansible_net_.*') | items2dict }}"` – Zeitounator Jan 10 '21 at 23:04

0 Answers0