networktocode.nautobot.lookup lookup – Queries and returns elements from Nautobot

Note

This lookup plugin is part of the networktocode.nautobot collection (version 4.1.1).

To install it, use: ansible-galaxy collection install networktocode.nautobot. You need further requirements to be able to use this lookup plugin, see Requirements for details.

To use it in a playbook, specify: networktocode.nautobot.lookup.

New in version 1.0.0: of networktocode.nautobot

Synopsis

  • Queries Nautobot via its API to return virtually any information capable of being held in Nautobot.

Requirements

The below requirements are needed on the local controller node that executes this lookup.

  • pynautobot

Terms

Parameter

Comments

Terms

string / required

The Nautobot object type to query

Parameters

Parameter

Comments

api_endpoint

string / required

The URL to the Nautobot instance to query

Configuration:

  • Environment variable: NAUTOBOT_URL

api_filter

string

The api_filter to use.

api_version

string

added in 4.1.0 of networktocode.nautobot

The Nautobot Rest API version to use.

plugin

string

The Nautobot plugin to query

raw_data

string

Whether to return raw API data with the lookup/query or whether to return a key/value dict

token

string

The API token created through Nautobot

This may not be required depending on the Nautobot setup.

Configuration:

  • Environment variable: NAUTOBOT_TOKEN

validate_certs

string

Whether or not to validate SSL of the Nautobot instance

Default: “true”

Examples

tasks:
  # query a list of devices
  - name: Obtain list of devices from Nautobot
    debug:
      msg: >
        "Device {{ item.value.display_name }} (ID: {{ item.key }}) was
         manufactured by {{ item.value.device_type.manufacturer.name }}"
    loop: "{{ query('networktocode.nautobot.lookup', 'devices',
                    api_endpoint='http://localhost/',
                    api_version='1.3',
                    token='<redacted>') }}"

# This example uses an API Filter
tasks:
  # query a list of devices
  - name: Obtain list of devices from Nautobot
    debug:
      msg: >
        "Device {{ item.value.display_name }} (ID: {{ item.key }}) was
         manufactured by {{ item.value.device_type.manufacturer.name }}"
    loop: "{{ query('networktocode.nautobot.lookup', 'devices',
                    api_endpoint='http://localhost/',
                    api_version='1.3',
                    api_filter='role=management tag=Dell',
                    token='<redacted>') }}"

# Fetch bgp sessions for R1-device
tasks:
  - name: "Obtain bgp sessions for R1-Device"
    debug:
      msg: "{{ query('networktocode.nautobot.lookup', 'bgp_sessions',
                     api_filter='device=R1-Device',
                     api_endpoint='http://localhost/',
                     api_version='1.3',
                     token='<redacted>',
                     plugin='mycustomstuff') }}"

Return Value

Key

Description

Return value

list / elements=string

list of composed dictionaries with key and value

Returned: success

Authors

  • Chris Mills (@cpmills1975)

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.