Git Product home page Git Product logo

ansible-collection-glpi's Introduction

Ansible collection for GLPI

Note: At the start this repository contains only a JSON inventory. The script has been moved to scripts/inventory for legacy.

This collection contains:

Installation

Theses python modules must be installed on the controller:

  • pyyaml for manipulating YAML files
  • yamlloader for keeping configuration order
  • glpi-api for interacting with GLPI REST API

There is a requirements file containing these dependencies so, if you don't care about clean integration to the system (using virtualenvs, distribution packages, ...):

$ sudo pip install -r requirements.txt

To install the collection:

# 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-collection-glpi,1.1.1

With a requirements file:

$ vim requirements.yml
---
collections:
- name: https://github.com/unistra/ansible-collection-glpi
  type: git
  version: 1.1.1

$ ansible-galaxy install -r requirements.yml

ansible-collection-glpi's People

Contributors

fmenabe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-collection-glpi's Issues

Add parameter to force `verify_certs=False` on GLPI()

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)

Use a configuration file for connection parameters

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?

Inventory Plugin and Ansible Galaxy Collection

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.

GLPI meta search

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

GLPI application token not provide - when using glpi_username and glpi_password

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:
   [...]

Adding new items is not working

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'}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.