Added config-context as an opt-in (#50343)
* Added config-context as opt-in * Added config-context description in the documentationpull/4420/head
parent
c65909d6db
commit
7dcacc1ce8
|
@ -11,6 +11,7 @@ DOCUMENTATION = '''
|
||||||
author:
|
author:
|
||||||
- Remy Leone (@sieben)
|
- Remy Leone (@sieben)
|
||||||
- Anthony Ruhier (@Anthony25)
|
- Anthony Ruhier (@Anthony25)
|
||||||
|
- Nikhil Singh Baliyan (@nikkytub)
|
||||||
short_description: NetBox inventory source
|
short_description: NetBox inventory source
|
||||||
description:
|
description:
|
||||||
- Get inventory hosts from NetBox
|
- 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.
|
- Allows connection when SSL certificates are not valid. Set to C(false) when certificates are not trusted.
|
||||||
default: True
|
default: True
|
||||||
type: boolean
|
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:
|
token:
|
||||||
required: True
|
required: True
|
||||||
description: NetBox token.
|
description: NetBox token.
|
||||||
|
@ -72,6 +80,7 @@ EXAMPLES = '''
|
||||||
plugin: netbox
|
plugin: netbox
|
||||||
api_endpoint: http://localhost:8000
|
api_endpoint: http://localhost:8000
|
||||||
validate_certs: True
|
validate_certs: True
|
||||||
|
config_context: False
|
||||||
group_by:
|
group_by:
|
||||||
- device_roles
|
- device_roles
|
||||||
query_filters:
|
query_filters:
|
||||||
|
@ -249,6 +258,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||||
|
|
||||||
def extract_config_context(self, host):
|
def extract_config_context(self, host):
|
||||||
try:
|
try:
|
||||||
|
if self.config_context:
|
||||||
url = urljoin(self.api_endpoint, "/api/dcim/devices/" + str(host["id"]))
|
url = urljoin(self.api_endpoint, "/api/dcim/devices/" + str(host["id"]))
|
||||||
device_lookup = self._fetch_information(url)
|
device_lookup = self._fetch_information(url)
|
||||||
return [device_lookup["config_context"]]
|
return [device_lookup["config_context"]]
|
||||||
|
@ -438,6 +448,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||||
self.api_endpoint = self.get_option("api_endpoint")
|
self.api_endpoint = self.get_option("api_endpoint")
|
||||||
self.timeout = self.get_option("timeout")
|
self.timeout = self.get_option("timeout")
|
||||||
self.validate_certs = self.get_option("validate_certs")
|
self.validate_certs = self.get_option("validate_certs")
|
||||||
|
self.config_context = self.get_option("config_context")
|
||||||
self.headers = {
|
self.headers = {
|
||||||
'Authorization': "Token %s" % token,
|
'Authorization': "Token %s" % token,
|
||||||
'User-Agent': "ansible %s Python %s" % (ansible_version, python_version.split(' ')[0]),
|
'User-Agent': "ansible %s Python %s" % (ansible_version, python_version.split(' ')[0]),
|
||||||
|
|
Loading…
Reference in New Issue