devon_mar.nblists.list lookup – Returns an array of IPs/prefixes

Note

This lookup plugin is part of the devon_mar.nblists collection (version 0.3.1).

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 devon_mar.nblists.

To use it in a playbook, specify: devon_mar.nblists.list.

New in devon_mar.nblists 0.1.0

Synopsis

Terms

Parameter

Comments

Terms

string / required

The NetBox lists endpoint(s). For example, ip-addresses, prefixes, tags/<tag-slug> or devices.

This is the part that comes after https://<your NetBox URL>/api/plugins/lists/.

See the plugin section of the API documentation of your NetBox instance for all endpoints.

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('devon_mar.nblists.list', key1=value1, key2=value2, ...) and query('devon_mar.nblists.list', key1=value1, key2=value2, ...)

Parameter

Comments

allow_empty_

boolean

If false, an exception will be raised if the returned list is empty.

Choices:

  • false ← (default)

  • true

Configuration:

key_value

dictionary

Arbitrary key=value pairs to be passed to NetBox lists as filters.

key_value is not an actual option for this lookup plugin.

Use a list or tuple as the value to use a filter more than once.

lists_path_

string

Path to the Netbox Lists API root. To be appended to url_.

Default: "/api/plugins/lists/"

Configuration:

token_

string

The NetBox API token.

Configuration:

url_

string / required

The URL to the NetBox instance with the Lists plugin.

Configuration:

Note

Configuration entries listed above for each entry type (Ansible variable, environment variable, and so on) 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. The entry types are also ordered by precedence from low to high priority order. For example, an ansible.cfg entry (further up in the list) is overwritten by an Ansible variable (further down in the list).

Notes

Note

  • When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters: lookup('devon_mar.nblists.list', term1, term2, key1=value1, key2=value2) and query('devon_mar.nblists.list', term1, term2, key1=value1, key2=value2)

Examples

- name: Get all NetBox IP addresses with the tag 'special'
  ansible.builtin.debug:
    msg: "{{ q('devon_mar.nblists.list', 'ip-addresses', tag='special') }}"

- name: Manually specify a token and URL.
  ansible.builtin.debug:
    msg: "{{ q('devon_mar.nblists.list', 'ip-addresses', tag='special', url_='https://netbox.example.com', token_='abc123') }}"

# Build an ACL using all NetBox prefixes with the role 'data'
- name: Build ACL 10
  ansible.builtin.set_fact:
    acl_10_aces: "{{ acl_10_aces | default([]) + ace }}"
  vars:
    ace:
      - grant: permit
        source:
          address: "{{ item | ansible.utils.ipaddr('network') }}"
          wildcard_bits: "{{ item | ansible.utils.ipaddr('wildcard') }}"
  loop: "{{ q('devon_mar.nblists.list', 'prefixes', role='data') }}"
- name: Ensure ACLs are configured
  cisco.ios.ios_acls:
    config:
      - afi: ipv4
        acls:
          - name: 10
            aces: "{{ acl_10_aces }}"

Return Value

Key

Description

Return value

list / elements=string

The list of IPs/prefixes.

Returned: success

Authors

  • Devon Mar (@devon-mar)