Added config-context as an opt-in (#50343)

* Added config-context as opt-in

* Added config-context description in the documentation
This commit is contained in:
nikkytub 2019-01-31 23:01:16 +01:00 committed by John R Barker
parent c65909d6db
commit 7dcacc1ce8

View file

@ -11,6 +11,7 @@ DOCUMENTATION = '''
author:
- Remy Leone (@sieben)
- Anthony Ruhier (@Anthony25)
- Nikhil Singh Baliyan (@nikkytub)
short_description: NetBox inventory source
description:
- Get inventory hosts from NetBox
@ -31,6 +32,13 @@ DOCUMENTATION = '''
- Allows connection when SSL certificates are not valid. Set to C(false) when certificates are not trusted.
default: True
type: boolean
config_context:
description:
- If True, it adds config-context in host vars.
- Config-context enables the association of arbitrary data to devices and virtual machines grouped by
region, site, role, platform, and/or tenant. Please check official netbox docs for more info.
default: False
type: boolean
token:
required: True
description: NetBox token.
@ -72,6 +80,7 @@ EXAMPLES = '''
plugin: netbox
api_endpoint: http://localhost:8000
validate_certs: True
config_context: False
group_by:
- device_roles
query_filters:
@ -249,9 +258,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
def extract_config_context(self, host):
try:
url = urljoin(self.api_endpoint, "/api/dcim/devices/" + str(host["id"]))
device_lookup = self._fetch_information(url)
return [device_lookup["config_context"]]
if self.config_context:
url = urljoin(self.api_endpoint, "/api/dcim/devices/" + str(host["id"]))
device_lookup = self._fetch_information(url)
return [device_lookup["config_context"]]
except Exception:
return
@ -438,6 +448,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
self.api_endpoint = self.get_option("api_endpoint")
self.timeout = self.get_option("timeout")
self.validate_certs = self.get_option("validate_certs")
self.config_context = self.get_option("config_context")
self.headers = {
'Authorization': "Token %s" % token,
'User-Agent': "ansible %s Python %s" % (ansible_version, python_version.split(' ')[0]),