3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
__pycache__
|
||||||
|
build
|
||||||
|
pages
|
||||||
13
CONTRIBUTING.md
Normal file
13
CONTRIBUTING.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Contirbution Guide
|
||||||
|
|
||||||
|
We welcome contributions.
|
||||||
|
|
||||||
|
|
||||||
|
## Inventory Plugin
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
|
||||||
|
# to test use
|
||||||
|
ansible-inventory -i nofusscomputing.itsm.centurion --list -vvv
|
||||||
|
|
||||||
|
```
|
||||||
@ -48,6 +48,7 @@ links:
|
|||||||
|
|
||||||
- [Merge Requests (Pull Requests)](https://gitlab.com/nofusscomputing/projects/ansible/collections/centurion_erp_collection/-/merge_requests)
|
- [Merge Requests (Pull Requests)](https://gitlab.com/nofusscomputing/projects/ansible/collections/centurion_erp_collection/-/merge_requests)
|
||||||
|
|
||||||
|
This Ansible collection is a companion collection for [Centurion ERP](https://nofusscomputing.com/projects/centurion_erp/)
|
||||||
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|||||||
5
ansible.cfg
Normal file
5
ansible.cfg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[defaults]
|
||||||
|
collections_path= ~/git/ansible_collections
|
||||||
|
|
||||||
|
[inventory]
|
||||||
|
enable_plugins = nofusscomputing.centurion.centurion
|
||||||
@ -11,7 +11,6 @@ about: https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernete
|
|||||||

|

|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
 
|
 
|
||||||
|
|
||||||
|
|
||||||
@ -21,4 +20,9 @@ about: https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernete
|
|||||||
|
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
This Ansible Collection is intended to compliement Centurion ERP.
|
This Ansible Collection is intended to compliement [Centurion ERP](../../../centurion_erp/index.md).
|
||||||
|
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- [Inventory plugin](./plugins/inventory.md)
|
||||||
|
|||||||
11
docs/projects/ansible/collection/centurion/plugins/index.md
Normal file
11
docs/projects/ansible/collection/centurion/plugins/index.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
title: Plugins
|
||||||
|
description: No Fuss Computings Companion Ansible Collection Centurion Plugins.
|
||||||
|
date: 2024-07-31
|
||||||
|
template: project.html
|
||||||
|
about: https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes
|
||||||
|
---
|
||||||
|
|
||||||
|
Available plugins include:
|
||||||
|
|
||||||
|
- [Inventory](./inventory.md)
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
title: Inventory
|
||||||
|
description: No Fuss Computings Companion Ansible Collection Centurion Inventory Plugin.
|
||||||
|
date: 2024-07-31
|
||||||
|
template: project.html
|
||||||
|
about: https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes
|
||||||
|
---
|
||||||
|
|
||||||
|
This inventory plugin obtains the data required from [Centurion ERP](../../../../centurion_erp/index.md) to build up an ansible inventory for all devices.
|
||||||
0
docs/projects/centurion_erp/index.md
Normal file
0
docs/projects/centurion_erp/index.md
Normal file
@ -29,6 +29,12 @@ nav:
|
|||||||
|
|
||||||
- projects/ansible/collection/centurion/index.md
|
- projects/ansible/collection/centurion/index.md
|
||||||
|
|
||||||
|
- Plugins:
|
||||||
|
|
||||||
|
- projects/ansible/collection/centurion/plugins/index.md
|
||||||
|
|
||||||
|
- projects/ansible/collection/centurion/plugins/inventory.md
|
||||||
|
|
||||||
|
|
||||||
- Operations:
|
- Operations:
|
||||||
|
|
||||||
|
|||||||
111
plugins/inventory/centurion.py
Normal file
111
plugins/inventory/centurion.py
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
from ansible.module_utils.common.text.converters import to_text
|
||||||
|
from ansible.module_utils.urls import open_url
|
||||||
|
from ansible.plugins.inventory import BaseInventoryPlugin
|
||||||
|
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: centurion
|
||||||
|
plugin_type: inventory
|
||||||
|
short_description: Centurion ERP Inventory
|
||||||
|
description:
|
||||||
|
- "An Inventory Plugin to fetch inventory from Centurion ERP."
|
||||||
|
options:
|
||||||
|
plugin:
|
||||||
|
description: token that ensures this is a source file for the 'centurion' plugin.
|
||||||
|
required: True
|
||||||
|
choices: ['nofusscomputing.centurion.centurion']
|
||||||
|
api_endpoint:
|
||||||
|
description: Endpoint of the Centurion API
|
||||||
|
required: true
|
||||||
|
env:
|
||||||
|
- name: CENTURION_API
|
||||||
|
token:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- NetBox API token to be able to read against NetBox.
|
||||||
|
env:
|
||||||
|
- name: CENTURION_TOKEN
|
||||||
|
validate_certs:
|
||||||
|
description:
|
||||||
|
- Allows skipping of validation of SSL certificates. Set to C(false) to disable certificate validation.
|
||||||
|
default: true
|
||||||
|
type: boolean
|
||||||
|
author:
|
||||||
|
- jon @jon_nfc
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class InventoryModule(BaseInventoryPlugin):
|
||||||
|
|
||||||
|
NAME = 'nofusscomputing.centurion.centurion'
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.headers = {
|
||||||
|
'Authorization': 'Token 7d501c956363e60df0cfd770db36f54226f079d707346f776ab31d5f40d16542'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def verify_file(self, path):
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_devices(self) -> dict:
|
||||||
|
|
||||||
|
self.display.v("Fetching Devices ")
|
||||||
|
|
||||||
|
response = open_url(
|
||||||
|
url = 'https://test.nofusscomputing.com/api/device/',
|
||||||
|
headers = self.headers,
|
||||||
|
validate_certs=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
devices = json.loads(to_text(response.read()))['results']
|
||||||
|
|
||||||
|
|
||||||
|
return devices
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_device_config(self, url: str) -> dict:
|
||||||
|
|
||||||
|
|
||||||
|
self.display.vv(f"Fetching Device Config {url} ")
|
||||||
|
|
||||||
|
response = open_url(
|
||||||
|
url = url,
|
||||||
|
headers = self.headers,
|
||||||
|
validate_certs=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
config = json.loads(to_text(response.read()))
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
def parse(self, inventory, loader, path, cache=True):
|
||||||
|
super().parse(inventory, loader, path)
|
||||||
|
|
||||||
|
devices = self.fetch_devices()
|
||||||
|
|
||||||
|
self.display.v(f"Parsing returned devices")
|
||||||
|
|
||||||
|
for device in devices:
|
||||||
|
|
||||||
|
|
||||||
|
self.display.vv(f"Adding device {device['name']} to inventory")
|
||||||
|
|
||||||
|
|
||||||
|
self.inventory.add_host(host=device['name'])
|
||||||
|
|
||||||
|
config = self.fetch_device_config(device['config'])
|
||||||
|
|
||||||
|
for key, val in config.items():
|
||||||
|
|
||||||
|
self.inventory.set_variable(device['name'], key, val)
|
||||||
Reference in New Issue
Block a user