Skip to content

Commit 35fc727

Browse files
Added error handling for fetching available choices for endpoints when encountering a ValueError which was due to a read-only token (#238)
1 parent 89e5e71 commit 35fc727

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ To keep the code simple, we only officially support the two latest releases of N
1414
- **pynetbox 4.2.5+**
1515
- Python 3.6+
1616
- Ansible 2.9+
17+
- NetBox write-enabled token
1718

1819
## Existing Modules
1920

plugins/module_utils/netbox_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,12 @@ def _fetch_choice_value(self, search, endpoint):
549549
app = self._find_app(endpoint)
550550
nb_app = getattr(self.nb, app)
551551
nb_endpoint = getattr(nb_app, endpoint)
552-
endpoint_choices = nb_endpoint.choices()
552+
try:
553+
endpoint_choices = nb_endpoint.choices()
554+
except ValueError:
555+
self._handle_errors(
556+
msg="Failed to fetch endpoint choices to validate against. This requires a write-enabled token. Make sure the token is write-enabled. If looking to fetch only information, use either the inventory or lookup plugin."
557+
)
553558

554559
choices = [x for x in chain.from_iterable(endpoint_choices.values())]
555560

0 commit comments

Comments
 (0)