Skip to content

Latest commit

 

History

History
624 lines (316 loc) · 12.2 KB

nb_lookup_lookup.rst

File metadata and controls

624 lines (316 loc) · 12.2 KB
orphan:

netbox.netbox.nb_lookup lookup -- Queries and returns elements from NetBox

Note

This lookup plugin is part of the netbox.netbox collection (version 3.17.0).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install netbox.netbox. You need further requirements to be able to use this lookup plugin, see :ref:`Requirements <ansible_collections.netbox.netbox.nb_lookup_lookup_requirements>` for details.

To use it in a playbook, specify: netbox.netbox.nb_lookup.

.. rst-class:: ansible-version-added

New in netbox.netbox 0.1.0

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

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

  • pynetbox
.. tabularcolumns:: \X{1}{3}\X{2}{3}

Parameter Comments
.. rst-class:: ansible-option-title

Terms

.. ansible-option-type-line::

  :ansible-option-type:`string` / :ansible-option-required:`required`




The NetBox object type to query

This describes keyword parameters of the lookup. These are the values key1=value1, key2=value2 and so on in the following examples: lookup('netbox.netbox.nb_lookup', key1=value1, key2=value2, ...) and query('netbox.netbox.nb_lookup', key1=value1, key2=value2, ...)

.. tabularcolumns:: \X{1}{3}\X{2}{3}

Parameter Comments
.. rst-class:: ansible-option-title

api_endpoint

.. ansible-option-type-line::

  :ansible-option-type:`string` / :ansible-option-required:`required`




The URL to the NetBox instance to query

.. rst-class:: ansible-option-line

:ansible-option-configuration:`Configuration:`

.. rst-class:: ansible-option-title

api_filter

.. ansible-option-type-line::

  :ansible-option-type:`string`




The api_filter to use. Filters should be key value pairs separated by a space.

.. rst-class:: ansible-option-title

key_file

.. ansible-option-type-line::

  :ansible-option-type:`string`




(DEPRECATED) - NetBox 2.11 and earlier only

The location of the private key tied to user account. Mutually exclusive with private_key.

.. rst-class:: ansible-option-title

plugin

.. ansible-option-type-line::

  :ansible-option-type:`string`




The NetBox plugin to query

.. rst-class:: ansible-option-title

private_key

.. ansible-option-type-line::

  :ansible-option-type:`string`




(DEPRECATED) - NetBox 2.11 and earlier only

The private key as a string. Mutually exclusive with key_file.

.. rst-class:: ansible-option-title

raw_data

.. ansible-option-type-line::

  :ansible-option-type:`boolean`




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

.. rst-class:: ansible-option-line

:ansible-option-choices:`Choices:`

.. rst-class:: ansible-option-title

token

.. ansible-option-type-line::

  :ansible-option-type:`string`




The API token created through NetBox

This may not be required depending on the NetBox setup.

.. rst-class:: ansible-option-line

:ansible-option-configuration:`Configuration:`

.. rst-class:: ansible-option-title

validate_certs

.. ansible-option-type-line::

  :ansible-option-type:`string`




Whether or not to validate SSL of the NetBox instance

.. rst-class:: ansible-option-line

:ansible-option-default-bold:`Default:` :ansible-option-default:`true`

Note

  • When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters: lookup('netbox.netbox.nb_lookup', term1, term2, key1=value1, key2=value2) and query('netbox.netbox.nb_lookup', term1, term2, key1=value1, key2=value2)
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>') }}"
.. tabularcolumns:: \X{1}{3}\X{2}{3}

Key Description
.. rst-class:: ansible-option-title

Return value

.. ansible-option-type-line::

  :ansible-option-type:`list` / :ansible-option-elements:`elements=string`

list of composed dictionaries with key and value

.. rst-class:: ansible-option-line

:ansible-option-returned-bold:`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.

Collection links

.. ansible-links::

  - title: "Issue Tracker"
    url: "https://github.com/netbox-community/ansible_modules/issues"
    external: true
  - title: "Repository (Sources)"
    url: "https://github.com/netbox-community/ansible_modules"
    external: true