networktocode.nautobot.lookup lookup – Queries and returns elements from Nautobot
Note
This lookup plugin is part of the networktocode.nautobot collection (version 5.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 networktocode.nautobot 1.0.0
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 |
---|---|
The Nautobot object type to query |
Keyword parameters
This describes keyword parameters of the lookup. These are the values key1=value1
, key2=value2
and so on in the following
examples: lookup('networktocode.nautobot.lookup', key1=value1, key2=value2, ...)
and query('networktocode.nautobot.lookup', key1=value1, key2=value2, ...)
Parameter |
Comments |
---|---|
The URL to the Nautobot instance to query Configuration:
|
|
The api_filter to use. |
|
The Nautobot Rest API version to use. |
|
The Nautobot plugin to query |
|
Whether to return raw API data with the lookup/query or whether to return a key/value dict |
|
The API token created through Nautobot This may not be required depending on the Nautobot setup. Configuration:
|
|
Whether or not to validate SSL of the Nautobot instance Default: :ansible-option-default:`true` |
Notes
Note
When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters:
lookup('networktocode.nautobot.lookup', term1, term2, key1=value1, key2=value2)
andquery('networktocode.nautobot.lookup', term1, term2, key1=value1, key2=value2)
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>') }}"
# This example uses an API Filter with Depth set to get additional details from the lookup
tasks:
# query a list of devices, getting API Depth of 1 to get additional details
# Note the space and the use of depth. Note the location_name is set to the namae of the location
- name: "Obtain Location Information from Nautobot and print some facts."
ansible.builtin.debug:
msg: >
"Location {{ item.value.name }} is {{ item.value['status']['name'] }} and has {{ item.value.prefix_count }} Prefixes and {{ item.value.vlan_count }} VLANs."
loop: "{{ query('networktocode.nautobot.lookup', 'locations',
url=NAUTOBOT_URL,
token=NAUTOBOT_TOKEN,
api_filter='name=' + location_name + ' depth=1',
) }}"
# 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 |
---|---|
list of composed dictionaries with key and value Returned: success |