Skip to content

Commit d3e3a0b

Browse files
Bug: netbox lookup: Error handling for invalid key file (#52)
1 parent 898c1d8 commit d3e3a0b

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env:
99
global:
1010
- COLLECTION_NAMESPACE: fragmentedpacket
1111
- COLLECTION_NAME: netbox_modules
12-
- COLLECTION_VERSION: 0.1.2
12+
- COLLECTION_VERSION: 0.1.3
1313

1414
matrix:
1515
include:

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace: fragmentedpacket
99
name: netbox_modules
1010

1111
# The version of the collection. Must be compatible with semantic versioning
12-
version: 0.1.2
12+
version: 0.1.3
1313

1414
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
1515
readme: README.md

plugins/lookup/netbox.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,17 @@ def run(self, terms, variables=None, **kwargs):
191191
if not isinstance(terms, list):
192192
terms = [terms]
193193

194-
netbox = pynetbox.api(
195-
netbox_api_endpoint,
196-
token=netbox_api_token,
197-
private_key_file=netbox_private_key_file,
198-
)
194+
try:
195+
netbox = pynetbox.api(
196+
netbox_api_endpoint,
197+
token=netbox_api_token,
198+
private_key_file=netbox_private_key_file,
199+
)
200+
except FileNotFoundError:
201+
raise AnsibleError(
202+
"%s cannot be found. Please make sure file exists."
203+
% netbox_private_key_file
204+
)
199205

200206
results = []
201207
for term in terms:

0 commit comments

Comments
 (0)