Note
This plugin is part of the netbox.netbox collection (version 2.0.0).
To install it use: ansible-galaxy collection install netbox.netbox
.
To use it in a playbook, specify: netbox.netbox.nb_lookup
.
New in version 2.9: of netbox.netbox
The below requirements are needed on the local controller node that executes this lookup.
Parameter | Choices/Defaults | Configuration | Comments |
---|---|---|---|
_terms string / required | The Netbox object type to query | ||
api_endpoint string / required | env:NETBOX_API env:NETBOX_URL | The URL to the Netbox instance to query | |
api_filter string | The api_filter to use. | ||
key_file string | The location of the private key tied to user account. | ||
plugin string | The Netbox 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 | env:NETBOX_TOKEN env:NETBOX_API_TOKEN | The API token created through Netbox This may not be required depending on the Netbox setup. | |
validate_certs string | Default: "yes" | Whether or not to validate SSL of the NetBox instance |
tasks: # query a list of devices - name: Obtain list of devices from Netbox debug: msg: > "Device {{ item.value.display_name }} (ID: {{ item.key }}) was manufactured by {{ item.value.device_type.manufacturer.name }}" loop: "{{ query('netbox.netbox.nb_lookup', 'devices', api_endpoint='http://localhost/', token='<redacted>') }}" # This example uses an API Filter tasks: # query a list of devices - name: Obtain list of devices from Netbox debug: msg: > "Device {{ item.value.display_name }} (ID: {{ item.key }}) was manufactured by {{ item.value.device_type.manufacturer.name }}" loop: "{{ query('netbox.netbox.nb_lookup', 'devices', api_endpoint='http://localhost/', api_filter='role=management tag=Dell'), token='<redacted>') }}" # Obtain a secret for R1-device tasks: - name: "Obtain secrets for R1-Device" debug: msg: "{{ query('netbox.netbox.nb_lookup', 'secrets', api_filter='device=R1-Device', api_endpoint='http://localhost/', token='<redacted>', key_file='~/.ssh/id_rsa') }}" # Fetch bgp sessions for R1-device tasks: - name: "Obtain bgp sessions for R1-Device" debug: msg: "{{ query('netbox.netbox.nb_lookup', 'bgp_sessions', api_filter='device=R1-Device', api_endpoint='http://localhost/', token='<redacted>', plugin='mycustomstuff') }}" msg: "{{ query('netbox.netbox.nb_lookup', 'secrets', api_filter='device=R1-Device', api_endpoint='http://localhost/', token='<redacted>', key_file='~/.ssh/id_rsa') }}"
Common return values are documented here, the following are the fields unique to this lookup:
Key | Returned | Description |
---|---|---|
_list list / elements=string | success | list of composed dictionaries with key and value |
© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.11/collections/netbox/netbox/nb_lookup_lookup.html