Skip to content

Commit

Permalink
Merge branch 'netbox-community:devel' into github-issue-netbox-commun…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ido-Don authored Oct 17, 2024
2 parents e7b6ca5 + 33f3bc0 commit 30cb663
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/1332-add-hostname_field-option.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- Add example for using ansible variables in lookup
2 changes: 2 additions & 0 deletions changelogs/fragments/1335-api-status-page-not-found.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- fix call /api/status/ instead /api/status in nb_inventory plugin. (https://github.com/netbox-community/ansible_modules/issues/1335).
2 changes: 1 addition & 1 deletion plugins/inventory/nb_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ def fetch_api_docs(self):
cached_api_version = None
cache = None

status = self._fetch_information(self.api_endpoint + "/api/status")
status = self._fetch_information(self.api_endpoint + "/api/status/")
netbox_api_version = ".".join(status["netbox-version"].split(".")[:2])

if version.parse(netbox_api_version) >= version.parse("3.5.0"):
Expand Down
14 changes: 14 additions & 0 deletions plugins/lookup/nb_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@
api_endpoint='http://localhost/',
api_filter='role=management tag=Dell'),
token='<redacted>') }}"
# This example uses an API Filter with a variable and jinja concatenation
- name: Set hostname fact
set_fact:
hostname: "my-server"
- name: Obtain details of a single device from NetBox
debug:
msg: >
"Device {{item.0.value.display}} (ID: {{item.0.key}}) was
manufactured by {{ item.0.value.device_type.manufacturer.name }}"
loop:
- '{{ query("netbox.netbox.nb_lookup", "devices",
api_endpoint="http://localhost/",
api_filter="name=" ~hostname,
token="<redacted>") }}'
"""

RETURN = """
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/targets/v3.5/tasks/netbox_lookup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,18 @@
vars:
query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')
}}"

- name: "NETBOX_LOOKUP 11: Device query by ansible variable"
ansible.builtin.set_fact:
hostname: "L2"

- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox"
ansible.builtin.debug:
msg: >
"Device {{item.0.value.display}} (ID: {{item.0.key}}) was
manufactured by {{ item.0.value.device_type.manufacturer.name }}"
loop:
- '{{ query("netbox.netbox.nb_lookup", "devices",
api_filter="name=" ~hostname,
api_endpoint="http://localhost:32768",
token="0123456789abcdef0123456789abcdef01234567") }}'
15 changes: 15 additions & 0 deletions tests/integration/targets/v3.6/tasks/netbox_lookup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,18 @@
vars:
query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')
}}"

- name: "NETBOX_LOOKUP 11: Device query by ansible variable"
ansible.builtin.set_fact:
hostname: "L2"

- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox"
ansible.builtin.debug:
msg: >
"Device {{item.0.value.display}} (ID: {{item.0.key}}) was
manufactured by {{ item.0.value.device_type.manufacturer.name }}"
loop:
- '{{ query("netbox.netbox.nb_lookup", "devices",
api_filter="name=" ~hostname,
api_endpoint="http://localhost:32768",
token="0123456789abcdef0123456789abcdef01234567") }}'
15 changes: 15 additions & 0 deletions tests/integration/targets/v3.7/tasks/netbox_lookup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,18 @@
vars:
query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')
}}"

- name: "NETBOX_LOOKUP 11: Device query by ansible variable"
ansible.builtin.set_fact:
hostname: "L2"

- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox"
ansible.builtin.debug:
msg: >
"Device {{item.0.value.display}} (ID: {{item.0.key}}) was
manufactured by {{ item.0.value.device_type.manufacturer.name }}"
loop:
- '{{ query("netbox.netbox.nb_lookup", "devices",
api_filter="name=" ~hostname,
api_endpoint="http://localhost:32768",
token="0123456789abcdef0123456789abcdef01234567") }}'
15 changes: 15 additions & 0 deletions tests/integration/targets/v4.0/tasks/netbox_lookup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,18 @@
vars:
query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')
}}"

- name: "NETBOX_LOOKUP 11: Device query by ansible variable"
ansible.builtin.set_fact:
hostname: "L2"

- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox"
ansible.builtin.debug:
msg: >
"Device {{item.0.value.display}} (ID: {{item.0.key}}) was
manufactured by {{ item.0.value.device_type.manufacturer.name }}"
loop:
- '{{ query("netbox.netbox.nb_lookup", "devices",
api_filter="name=" ~hostname,
api_endpoint="http://localhost:32768",
token="0123456789abcdef0123456789abcdef01234567") }}'
15 changes: 15 additions & 0 deletions tests/integration/targets/v4.1/tasks/netbox_lookup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,18 @@
vars:
query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')
}}"

- name: "NETBOX_LOOKUP 11: Device query by ansible variable"
ansible.builtin.set_fact:
hostname: "L2"

- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox"
ansible.builtin.debug:
msg: >
"Device {{item.0.value.display}} (ID: {{item.0.key}}) was
manufactured by {{ item.0.value.device_type.manufacturer.name }}"
loop:
- '{{ query("netbox.netbox.nb_lookup", "devices",
api_filter="name=" ~hostname,
api_endpoint="http://localhost:32768",
token="0123456789abcdef0123456789abcdef01234567") }}'

0 comments on commit 30cb663

Please sign in to comment.