unistra / ansible-collection-glpi

Ansible dynamic inventory for GLPI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inventory Plugin and Ansible Galaxy Collection

jplitza opened this issue · comments

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:

  1. Add collection to requirements.yml:
    ---
    collections:
    - unistra.glpi
  2. Run ansible-galaxy install -r requirements.yml
  3. Add inventory plugin name and config path to ansible.cfg:
    [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.

I take time to look at it and it was in fact not so hard to transform the inventory to a dedicated plugin and make it a collection. You can see the result in the @collection branch.

To test it:

# set collections directory to the current directory (default is ~/.ansible/collections)
$ export ANSIBLE_COLLECTIONS_PATH=$(pwd)
$ ansible-galaxy collection install git+https://github.com/unistra/ansible-inventory-glpi,collection
$ vim ansible.cfg
[inventory]
enable_plugins = unistra.glpi.inv
$ vim glpi.yml
---                                                                                                    
plugin: unistra.glpi.inv

glpi_url: <FIXME>
glpi_apptoken: <FIXME>
glpi_auth: <FIXME>

queries:
# what was contained in the configuration file for the JSON inventory
  mygroup:
    itemtype: 
    criteria:
    ...

# use -vvv to see plugin errors
$ ansible -i glpi.yml all --list-hosts

I still need to update the documentation and I'm asking myself if a new repository should not be created (or at least rename this repo). The new repository would be centered on the collection and could contains other resources (like a module to update information on GLPI). This will also allow to keep the JSON inventory as legacy. So there may be changes later in that area.

In any case, from the user perspective, the python-glpi-api module should also be pushed on PyPi and the collection on Ansible Galaxy. My organization already have an account for PyPi but I need to retrieve the ids from the developers and we need to create an account on Galaxy. This should be discussed before and I will not be working in the next three weeks, so this part will not be done before next year!

If you think some things could be improved or have any comment, feedback is welcomed!

This is great news, thank you!
I don't know how collections are organized and agree that the collection shouldn't be based on this repo. I expected a collection to contain some metadata and reference other repositories for plugins, roles etc., but if it has to be monorepo, it should be renamed.
Also, a plugin for changing stuff in GLPI would be great, too! I have this on my todo list to connect harddisks to computers by serial number discovered from Ansible.

👍 It would be very nice to package this nice plugin as an Ansible Collection!

It was already done but buried in a a branch! I merged the branch to master so you should find it directly.

I've also pushed the glpi-api dependency to Pypi so installation of dependencies should be easier.

Perfect! Thank you.