NetBox Ansible Collection: Platforms
Platforms are an optional item when adding devices into NetBox. The platform is the OS that you are going to be using. Most often this is used to help identify which driver your automation platform is going to be using. Specifically the slug of the platform is what needs to match. So in the terms of Ansible (since we are using Ansible to populate NetBox), you will want to set Cisco IOS devices to ios. By having the slug match the automation platform name you have that information in your inventory. For these reasons I strongly recommend setting the Platform for devices.
Note
This post was created when NetBox was an open source project used often in my automation framework. I have moved on to using Nautobot due to the project vision and providing a methodology that will drive network automation forward further. You may want to take a look at it yourself.
Module Documentation#
This module does require pynetbox to execute properly
Environment#
For this demo, here are the versions shown:
Component | Version |
---|---|
NetBox | v2.9.9 (NetBox Docker) |
NetBox Ansible Collection | v1.1.0 |
pynetbox | 5.1.0 |
Data File#
Now that you may want to have a different slug than what is displayed, the data structure is getting slightly more complex than the manufacturers file. There will be a list of dictionaries, where the dictionary has three keys: name, slug, and manufacturer.
---
platforms:
- name: Arista EOS
slug: eos
manufacturer: Arista
- name: Cisco IOS
slug: ios
manufacturer: Cisco
- name: JUNOS
slug: junos
manufacturer: Juniper
Example#
Example - Adding Devices#
Getting started I already have a Cisco manufacturer included from a different demo. This will not hurt what is being demonstrated here. The task to add a manufacturer looks like:
---
- name: "ADD PLATFORMS TO NETBOX"
hosts: localhost
connection: local
gather_facts: false # No gathering facts about the container execution env
tasks:
- name: "05 - ADD PLATFORMS"
netbox.netbox.netbox_platform:
netbox_url: "{{ lookup('env', 'NETBOX_URL') }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') }}"
data:
name: "{{ item['name'] }}"
loop: "{{ platforms }}"
Example - Execution#
This execution shows that all of the platforms are added.
The second execution of playbook shows that with these three settings the module is idempotent:
Now you see all of them showing up in NetBox.
When editing the Cisco platform you see the result visually.
Summary#
Platforms are one of the items that you will strongly want to get updated into NetBox. By associating a device with a platform you can then use it in the inventory plugins to identify things such as the ansible_network_os
dynamically. Need to have a new platform to test things with, just create a new platform, change a few settings, and the information is dynamically available within your playbooks.
Hope this has helped. If so, let me know with a comment below or give a thumbs up on the post.
Share on Share on Share on Share on Share on