feat(inventory): Create groups from organizations
!7 nofusscomputing/projects/centurion_erp!45 closes #5
This commit is contained in:
@ -23,6 +23,11 @@ options:
|
|||||||
required: true
|
required: true
|
||||||
env:
|
env:
|
||||||
- name: CENTURION_API
|
- name: CENTURION_API
|
||||||
|
organization_groups:
|
||||||
|
description:
|
||||||
|
- Create groups from organization names. Uses format C(organization_<organization.name>).
|
||||||
|
default: true
|
||||||
|
type: boolean
|
||||||
token:
|
token:
|
||||||
required: false
|
required: false
|
||||||
description:
|
description:
|
||||||
@ -51,6 +56,7 @@ api_endpoint: http://localhost:8000
|
|||||||
token: <token value here>
|
token: <token value here>
|
||||||
validate_certs: false
|
validate_certs: false
|
||||||
|
|
||||||
|
organization_groups: true
|
||||||
|
|
||||||
# Example Ansible Tower credential Input Configuration:
|
# Example Ansible Tower credential Input Configuration:
|
||||||
|
|
||||||
@ -147,6 +153,7 @@ class InventoryModule(BaseInventoryPlugin):
|
|||||||
self.api_endpoint = self.get_option("api_endpoint").strip("/")
|
self.api_endpoint = self.get_option("api_endpoint").strip("/")
|
||||||
self.token = self.get_option("token")
|
self.token = self.get_option("token")
|
||||||
self.validate_certs = self.get_option("validate_certs")
|
self.validate_certs = self.get_option("validate_certs")
|
||||||
|
self.organization_groups = self.get_option("organization_groups")
|
||||||
|
|
||||||
self.headers = {
|
self.headers = {
|
||||||
'Authorization': f'Token {self.token}'
|
'Authorization': f'Token {self.token}'
|
||||||
@ -164,6 +171,42 @@ class InventoryModule(BaseInventoryPlugin):
|
|||||||
|
|
||||||
self.inventory.add_host(host=device['name'])
|
self.inventory.add_host(host=device['name'])
|
||||||
|
|
||||||
|
if len(device['groups']):
|
||||||
|
|
||||||
|
for group in device['groups']:
|
||||||
|
|
||||||
|
group_name = to_safe_group_name(
|
||||||
|
name = str(group['name']).lower(),
|
||||||
|
replacer = '_',
|
||||||
|
force = True,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.inventory.add_group(
|
||||||
|
group = group_name
|
||||||
|
)
|
||||||
|
|
||||||
|
self.inventory.add_host(
|
||||||
|
host = device['name'],
|
||||||
|
group = group_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.organization_groups:
|
||||||
|
|
||||||
|
organization_group_name = to_safe_group_name(
|
||||||
|
name = 'organization_' + str(device['organization']['name']).lower(),
|
||||||
|
replacer = '_',
|
||||||
|
force = True,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.inventory.add_group(
|
||||||
|
group = organization_group_name
|
||||||
|
)
|
||||||
|
|
||||||
|
self.inventory.add_host(
|
||||||
|
host = device['name'],
|
||||||
|
group = organization_group_name,
|
||||||
|
)
|
||||||
|
|
||||||
# see #5
|
# see #5
|
||||||
# config = self.fetch_device_config(device['config'])
|
# config = self.fetch_device_config(device['config'])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user