unistra / ansible-collection-glpi Goto Github PK
View Code? Open in Web Editor NEWAnsible dynamic inventory for GLPI.
License: GNU General Public License v3.0
Ansible dynamic inventory for GLPI.
License: GNU General Public License v3.0
Hi! I am using your module to manage GLPI from Ansible. Thank you very much!
Looks like you forgot to add add
directives to the plugins/modules/api.py.
# add
if 'add' in ignore_actions:
return {'changed': False, 'action': 'added',
'msg': "action ignored as specified by 'ignore_actions'"
"parameter"}
# I`ve made like this
doc = {}
doc.update(values)
glpi.add(itemtype, doc)
# the end
return {'changed': True, 'action': 'added'}
Hello,
When we want to use glpi_username and glpi_password instead of glpi_apptoken and glpi_usertoken we get the following error :
[WARNING]: * Failed to parse /home/vagrant/inventory_glpi.yml with ansible_collections.unistra.glpi.plugins.inventory.inv plugin: GLPI application token not provided
Here is my config file :
---
plugin: unistra.glpi.inv
glpi_url: https://example.org/apirest.php
glpi_verify_certs: false
glpi_username: dgiordana
glpi_password: "obviouslynotmypassword"
queries:
[...]
Parameters for connecting to GLPI are managed by the CLI, using some environment variables as default values of theses options.
Usage of dynamic inventories with Ansible commands (ansible
, ansible-playbook
) does not allow to pass option to the inventory script and environment variables needs to be defined.
It may be preferable to use a (YAML?) configuration file for defining connection parameters. As there is already a configuration file for groups configuration, should theses files be merged?
One of our GLPI is internal only, and we set it up with a self-signed TLS certificate.
It would be nice if you could add a configuration parameter glpi_verify_certs
to disable certificate checking.
For now, I modified ansible_collections/unistra/glpi/plugins/inventory/inv.py
at line 103 to add , verify_certs=False
:
self.glpi = GLPI(url=str(glpi_url), apptoken=str(glpi_apptoken), auth=str(glpi_auth), verify_certs=False)
It would be nice to be able to use vault variable in the inventory file to secure sensitve data (such as glpi_apptoken and glpi_usertoken)
It has been done on vmware plugin ansible-collections/community.vmware#854
I'll try to take a look and do it by myself then create a PR.
Hello
I'm actually integrating your work in our ansible setup, to get inventory from GLPI API. works fine.
One problem though : the fact that it's not possible to get elements by name (uid_cols=true).
The inherent problem is when using meta search : if a meta filed has the same id in its category, it overwrites the result.
example when trying to get computers with a specific version of a software installed :
GET PARAMS :
uid_cols:1
criteria[0][field]:5161
criteria[0][searchtype]:contains
criteria[0][value]:freepbx
criteria[1][link]:AND
criteria[1][meta]:true
criteria[1][itemtype]:Software
criteria[1][field]:1
criteria[1][searchtype]:contains
criteria[1][value]:freepbx-module-core
criteria[2][link]:AND
criteria[2][meta]:true
criteria[2][itemtype]:Software
criteria[2][field]:5
criteria[2][searchtype]:contains
criteria[2][value]:^16
result of query :
"data": [
{
"Computer.name": "117-freepbx",
"Computer.Entity.completename": "/",
"Computer.Location.completename": null,
"Computer.State.completename": "actif",
"Computer.ComputerType.name": "QEMU",
"Computer.PluginFusioninventoryInventoryComputerComputer.last_fusioninventory_update": "2024-04-03 17:00:50",
"Computer.comment": null,
"Computer.ComputerModel.name": "Standard PC (i440FX + PIIX, 1996)",
"Computer.Item_OperatingSystem.OperatingSystem.name": "Debian GNU/Linux",
"Computer.Item_OperatingSystem.OperatingSystemVersion.name": "12.5",
"Computer.ComputerVirtualMachine.name": null,
"Computer.PluginFusioninventoryAgent.tag": "freepbx location_client",
"Software.name": "freepbx-module-core",
"Software.SoftwareVersion.name": "freepbx-module-core - 16.0.68.20"
},
...
but if I remove the "uid_cols:1" I get this result, which does not display anymore the targeted hostname :
"data": [
{
"1": "freepbx-module-core",
"80": "/",
"3": null,
"31": "actif",
"4": "QEMU",
"5150": "2024-04-03 17:00:50",
"16": null,
"40": "Standard PC (i440FX + PIIX, 1996)",
"45": "Debian GNU/Linux",
"46": "12.5",
"160": null,
"5161": "freepbx location_client",
"5": "freepbx-module-core - 16.0.68.20"
},
...
because "Software.name" has id 1 in software itemtype.
Is there any workaround ?
Regards
The problem is probably in the low-level library python-glpi-api.
I think it would be nice to have an Ansible Galaxy Collection for GLPI, where this inventory source could be included as an inventory plugin. To my understanding, that would greatly improve and simplify the integration:
---
collections:
- unistra.glpi
ansible-galaxy install -r requirements.yml
[defaults]
inventory = ./glpi-api.yml
[inventory]
enable_plugins = unistra.glpi.inventory
I don't know what has to be changed on the code side to be a valid inventory plugin (instead of outputting JSON), but combined with #1 this would make for a nice integration from the user-perspective.
Currently, I'm not even sure what's the best way to integrate this inventory source. As it's not a Python module, I currently include it as a submodule, but that makes handling requirements harder, and the config file is (by default) searched inside the submodule instead of the playbook dir.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.