Use Centreon configuration as an Ansible dynamic inventory.
This project is composed of an HTTP API implemented with Laravel and an inventory script written in python.
The inventory script ans its config file needs to be installed on your Ansible host and calls the HTTP API.
There is no restiction on where the later can be installed.
It relies on Transatel/lib-eloquent-centreon for accessing Centreon's databases and calling its internal REST API.
There is caching of the list of available metrics (i.e. services providing perf data).
To force the reconstruction of the cache, just send:
DELETE localhost:8000/ansible/inventory/cache
Centreon's Host Templates are mapped as Ansible Host Groups.
Centron Host Macros are mapped as Ansible Inventory Variable.
Macro override from multiple Host Template are taken into account.
Multi-level inheritance as well.
Copy the .env.example file into a new .env
file.
There are are the keys you might want to edit (if you changed default values).
After modifying them, one might want to do a php artisan config:clear
to ensure older cached values are purged.
Key | Description |
---|---|
DB_HOST_CENTREON | Domain Name or IP address to connect to the database |
DB_PORT_CENTREON | Port to connect to the database |
DB_DATABASE_CENTREON | Name of the schema |
DB_USERNAME_CENTREON | Username to connect to the database |
DB_PASSWORD_CENTREON | Password to connect to the database |
The configuration file centreon.ini has the following keys:
Key | Description |
---|---|
centreon.url | URL to access the API |
It needs to be dropped in the /etc/ansible/ folder or your ansible host.
$ composer update
You can quick start.
$ php -S 0.0.0.0:8000 -t public
<VirtualHost *:8000>
ServerName ansible-dynamic-inventory-centreon
DocumentRoot "/opt/ansible-dynamic-inventory-centreon/public"
<Directory "/opt/ansible-dynamic-inventory-centreon/public/">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
GET localhost:8000/inventory/list
After updating the URL of the backend in the configuration file, call:
$ centreon.py --list
You can then call the script via Ansible. Assuming your centreon.py got dropped in /etc/ansible/:
$ # ansible >= 2.4
$ ansible-inventory -i /etc/ansible/centreon.py --list-hosts
$ # ansible < 2.4
$ ansible '*' -i /etc/ansible/centreon.py --list-hosts
In your /etc/ansible/ansible.cfg or ~/ansible.cfg configuration file:
inventory = /etc/ansible/centreon.py