Skip to content

Commit 33f3bc0

Browse files
authored
Merge pull request #1332 from martbhell/nb_lookup_with_variable_example
nb_lookup.py: Add example for lookup with variable
2 parents c76986f + dd976fc commit 33f3bc0

File tree

7 files changed

+91
-0
lines changed

7 files changed

+91
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- Add example for using ansible variables in lookup

plugins/lookup/nb_lookup.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@
102102
api_endpoint='http://localhost/',
103103
api_filter='role=management tag=Dell'),
104104
token='<redacted>') }}"
105+
# This example uses an API Filter with a variable and jinja concatenation
106+
- name: Set hostname fact
107+
set_fact:
108+
hostname: "my-server"
109+
- name: Obtain details of a single device from NetBox
110+
debug:
111+
msg: >
112+
"Device {{item.0.value.display}} (ID: {{item.0.key}}) was
113+
manufactured by {{ item.0.value.device_type.manufacturer.name }}"
114+
loop:
115+
- '{{ query("netbox.netbox.nb_lookup", "devices",
116+
api_endpoint="http://localhost/",
117+
api_filter="name=" ~hostname,
118+
token="<redacted>") }}'
105119
"""
106120

107121
RETURN = """

tests/integration/targets/v3.5/tasks/netbox_lookup.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,18 @@
8888
vars:
8989
query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')
9090
}}"
91+
92+
- name: "NETBOX_LOOKUP 11: Device query by ansible variable"
93+
ansible.builtin.set_fact:
94+
hostname: "L2"
95+
96+
- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox"
97+
ansible.builtin.debug:
98+
msg: >
99+
"Device {{item.0.value.display}} (ID: {{item.0.key}}) was
100+
manufactured by {{ item.0.value.device_type.manufacturer.name }}"
101+
loop:
102+
- '{{ query("netbox.netbox.nb_lookup", "devices",
103+
api_filter="name=" ~hostname,
104+
api_endpoint="http://localhost:32768",
105+
token="0123456789abcdef0123456789abcdef01234567") }}'

tests/integration/targets/v3.6/tasks/netbox_lookup.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,18 @@
8888
vars:
8989
query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')
9090
}}"
91+
92+
- name: "NETBOX_LOOKUP 11: Device query by ansible variable"
93+
ansible.builtin.set_fact:
94+
hostname: "L2"
95+
96+
- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox"
97+
ansible.builtin.debug:
98+
msg: >
99+
"Device {{item.0.value.display}} (ID: {{item.0.key}}) was
100+
manufactured by {{ item.0.value.device_type.manufacturer.name }}"
101+
loop:
102+
- '{{ query("netbox.netbox.nb_lookup", "devices",
103+
api_filter="name=" ~hostname,
104+
api_endpoint="http://localhost:32768",
105+
token="0123456789abcdef0123456789abcdef01234567") }}'

tests/integration/targets/v3.7/tasks/netbox_lookup.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,18 @@
8888
vars:
8989
query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')
9090
}}"
91+
92+
- name: "NETBOX_LOOKUP 11: Device query by ansible variable"
93+
ansible.builtin.set_fact:
94+
hostname: "L2"
95+
96+
- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox"
97+
ansible.builtin.debug:
98+
msg: >
99+
"Device {{item.0.value.display}} (ID: {{item.0.key}}) was
100+
manufactured by {{ item.0.value.device_type.manufacturer.name }}"
101+
loop:
102+
- '{{ query("netbox.netbox.nb_lookup", "devices",
103+
api_filter="name=" ~hostname,
104+
api_endpoint="http://localhost:32768",
105+
token="0123456789abcdef0123456789abcdef01234567") }}'

tests/integration/targets/v4.0/tasks/netbox_lookup.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,18 @@
8888
vars:
8989
query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')
9090
}}"
91+
92+
- name: "NETBOX_LOOKUP 11: Device query by ansible variable"
93+
ansible.builtin.set_fact:
94+
hostname: "L2"
95+
96+
- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox"
97+
ansible.builtin.debug:
98+
msg: >
99+
"Device {{item.0.value.display}} (ID: {{item.0.key}}) was
100+
manufactured by {{ item.0.value.device_type.manufacturer.name }}"
101+
loop:
102+
- '{{ query("netbox.netbox.nb_lookup", "devices",
103+
api_filter="name=" ~hostname,
104+
api_endpoint="http://localhost:32768",
105+
token="0123456789abcdef0123456789abcdef01234567") }}'

tests/integration/targets/v4.1/tasks/netbox_lookup.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,18 @@
8888
vars:
8989
query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')
9090
}}"
91+
92+
- name: "NETBOX_LOOKUP 11: Device query by ansible variable"
93+
ansible.builtin.set_fact:
94+
hostname: "L2"
95+
96+
- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox"
97+
ansible.builtin.debug:
98+
msg: >
99+
"Device {{item.0.value.display}} (ID: {{item.0.key}}) was
100+
manufactured by {{ item.0.value.device_type.manufacturer.name }}"
101+
loop:
102+
- '{{ query("netbox.netbox.nb_lookup", "devices",
103+
api_filter="name=" ~hostname,
104+
api_endpoint="http://localhost:32768",
105+
token="0123456789abcdef0123456789abcdef01234567") }}'

0 commit comments

Comments
 (0)