Collection

Netbox

Installation

  • ansible-galaxy collection install netbox.netbox

  • ansible-galaxy collection list

Configuration

# netbox_inv.yml
plugin: "netbox.netbox.nb_inventory"
validate_certs: false
api_endpoint: http://192.168.0.115:8000
token: 98f02164d0ef623965a8992bece02c3cc2ca12be

# Create Ansible groups based on device roles: Router and Switch
group_by:
  - device_roles
  - platforms


# don't need to pull down extra config data
config_context: false

# Only return devices with management IPs (ignore passive devices)
# The plug will also store this as "ansible_host"
device_query_filters:
  - has_primary_ip: "true"

# Additionally, have the plugin include the network OS
compose:
  ansible_network_os: platform.slug

Parse Genie

  • ansible-galaxy install clay584.parse_genie

  • https://developer.cisco.com/codeexchange/github/repo/clay584/parse_genie/

  • Ansible considers IOS and IOS-XE the same and therefore the ansible_network_os = ios, but Genie needs to know specifically if it is IOS or IOS-XE in order to parse the CLI output correctly. If you pass ansible_network_os to this filter plugin, and it is equal to ios, parse_genie will try to parse it with Genie using os=ios first, and if that fails,it will then try to parse it with os=iosxe. It may be best to pass the real OS to the parse_genie. This can be done by keeping another inventory variable or host_var to specify the Genie OS for each network device and using that variable as the OS for the parse_genie.

Usage

  • Make sure to read in the parse_genie role before you attempt to use it later in your playbook.

Example

Generic Tabular Parsing

  • For those show commands where there is not a parser that has been built by Cisco, there is the generic tabular parsing functionality. For more information on the Genie tabular parsing functionality, see their oper_fill_tabular (https://pubhub.devnetcloud.com/media/pyats-packages/docs/parsergen/tabular/tabular.html) documentation.

Reference

  • https://docs.ansible.com/ansible/latest/collections/netbox/netbox/nb_inventory_inventory.html#ansible-collections-netbox-netbox-nb-inventory-inventory

  • https://www.ansible.com/blog/using-netbox-for-ansible-source-of-truth

  • http://blog.networktocode.com/post/ansible-constructed-inventory/

Last updated