|
6 | 6 | ##
|
7 | 7 | - name: "NETBOX_LOOKUP 1: Lookup returns exactly two sites"
|
8 | 8 | assert:
|
9 |
| - that: "{{ query_result|count }} == 3" |
| 9 | + that: query_result == "3" |
10 | 10 | vars:
|
11 |
| - query_result: "{{ query('netbox.netbox.nb_lookup', 'sites', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}" |
| 11 | + query_result: "{{ query('netbox.netbox.nb_lookup', 'sites', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')|count }}" |
12 | 12 |
|
13 | 13 | - name: "NETBOX_LOOKUP 2: Query doesn't return Wibble (sanity check json_query)"
|
14 | 14 | assert:
|
15 |
| - that: "{{ query_result|community.general.json_query('[?value.display==`Wibble`]')|count }} == 0" |
| 15 | + that: query_result == "0" |
16 | 16 | vars:
|
17 |
| - query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}" |
| 17 | + query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')|community.general.json_query('[?value.display==`Wibble`]')|count}}" |
18 | 18 |
|
19 | 19 | - name: "NETBOX_LOOKUP 3: Device query returns exactly one TestDeviceR1"
|
20 | 20 | assert:
|
21 |
| - that: "{{ query_result|community.general.json_query('[?value.display==`TestDeviceR1`]')|count }} == 1" |
| 21 | + that: query_result == "1" |
22 | 22 | vars:
|
23 |
| - query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}" |
| 23 | + query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')|community.general.json_query('[?value.display==`TestDeviceR1`]')|count }}" |
24 | 24 |
|
25 | 25 | - name: "NETBOX_LOOKUP 4: VLAN ID 400 can be queried and is named 'Test VLAN'"
|
26 | 26 | assert:
|
27 |
| - that: "{{ (query_result|community.general.json_query('[?value.vid==`400`].value.name'))[0] == 'Test VLAN' }}" |
| 27 | + that: query_result == 'Test VLAN' |
28 | 28 | vars:
|
29 |
| - query_result: "{{ query('netbox.netbox.nb_lookup', 'vlans', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}" |
| 29 | + query_result: "{{ (query('netbox.netbox.nb_lookup', 'vlans', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')|community.general.json_query('[?value.vid==`400`].value.name'))[0] }}" |
30 | 30 |
|
31 | 31 | - name: "NETBOX_LOOKUP 5: Add one of two devices for lookup filter test."
|
32 | 32 | netbox.netbox.netbox_device:
|
|
58 | 58 |
|
59 | 59 | - name: "NETBOX_LOOKUP 7: Device query returns exactly the L2 device"
|
60 | 60 | assert:
|
61 |
| - that: "{{ query_result|community.general.json_query('[?value.display==`L2`]')|count }} == 1" |
| 61 | + that: query_result == "1" |
62 | 62 | vars:
|
63 |
| - query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='role=core-switch tag=lookup', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}" |
| 63 | + query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='role=core-switch tag=lookup', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567')|community.general.json_query('[?value.display==`L2`]')|count }}" |
64 | 64 |
|
65 | 65 | - name: "NETBOX_LOOKUP 8: Device query specifying raw data returns payload without key/value dict"
|
66 | 66 | assert:
|
67 |
| - that: "{{ query_result|community.general.json_query('[?display==`L2`]')|count }} == 1" |
| 67 | + that: query_result == "1" |
68 | 68 | vars:
|
69 |
| - query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='role=core-switch tag=lookup', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567', raw_data=True) }}" |
| 69 | + query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='role=core-switch tag=lookup', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567', raw_data=True)|community.general.json_query('[?display==`L2`]')|count }}" |
70 | 70 |
|
71 | 71 | - name: "NETBOX_LOOKUP 9: Device query specifying multiple sites, Make sure L1 and L2 are in the results"
|
72 | 72 | assert:
|
73 | 73 | that:
|
74 |
| - - "'L1' in {{ query_result |community.general.json_query('[*].display') }}" |
75 |
| - - "'L2' in {{ query_result |community.general.json_query('[*].display') }}" |
| 74 | + - "'L1' in query_result" |
| 75 | + - "'L2' in query_result" |
76 | 76 | vars:
|
77 |
| - query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='role=core-switch site=test-site site=test-site2', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567', raw_data=True) }}" |
| 77 | + query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='role=core-switch site=test-site site=test-site2', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567', raw_data=True)|community.general.json_query('[*].display') }}" |
78 | 78 |
|
79 | 79 | - name: "NETBOX_LOOKUP 10: Device query by ID"
|
80 | 80 | assert:
|
81 |
| - that: |
82 |
| - - "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}" |
| 81 | + that: query_result |
| 82 | + vars: |
| 83 | + query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}" |
0 commit comments