74
docs/projects/nfc_glpi/config_from_code.md
Normal file
74
docs/projects/nfc_glpi/config_from_code.md
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
---
|
||||||
|
title: Config as code
|
||||||
|
description: How to use No Fuss Computings Ansible role to configure GLPI from configuration as code.
|
||||||
|
date: 2023-07-28
|
||||||
|
template: project.html
|
||||||
|
about: https://gitlab.com/nofusscomputing/projects/ansible/nfc_glpi
|
||||||
|
---
|
||||||
|
|
||||||
|
To configure GLPI using this role, the config/settings are saved as json files. The workflow to create the json files, is to (preferably within a test environment) make the required setting changes in GLPI using the GUI. one the changes have been made, conduct an API `GET` query to GLPI for the item you changed. The JSON body that is returned, is placed within the Config file (detailed below) under path `.body`. You must however, remove any fields that are not required, for example dynamic fields (fields that update themselves or are auto created) for example date fields.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Config files Example
|
||||||
|
|
||||||
|
Each tab provides an example of the JSON file layout, including any additional variables. Any variable listed at path `.` that are empty strings, you would complete with the items name as it is exactly within GLPI. These fields are used to fetch the itm_id of the field by name. this enables having the config saved in a more human readable format. For example, for the field `entities_id` you would complete it as `"entities_id": "My entity name"`.
|
||||||
|
|
||||||
|
=== "AuthLDAP"
|
||||||
|
|
||||||
|
``` json title="example.json" linenums="1
|
||||||
|
{
|
||||||
|
"api_path": "AuthLDAP",
|
||||||
|
"body": {
|
||||||
|
// JSON from API Query
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
=== "Entity"
|
||||||
|
|
||||||
|
``` json title="example.json" linenums="1
|
||||||
|
{
|
||||||
|
"api_path": "Entity",
|
||||||
|
"entities_id": "",
|
||||||
|
"body": {
|
||||||
|
// JSON from API Query
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "ITILCategory"
|
||||||
|
|
||||||
|
``` json title="example.json" linenums="1
|
||||||
|
{
|
||||||
|
"api_path": "ITILCategory",
|
||||||
|
"users_id": "",
|
||||||
|
"itilcategories_id": "",
|
||||||
|
"entities_id": "",
|
||||||
|
"tickettemplates_id_demand": "",
|
||||||
|
"body": {
|
||||||
|
// JSON from API Query
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Profile"
|
||||||
|
|
||||||
|
``` json title="example.json" linenums="1
|
||||||
|
{
|
||||||
|
"api_path": "Profile",
|
||||||
|
"body": {
|
||||||
|
// JSON from API Query
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
With the config files structured as per the examples, within your playbook(s), load the json files in a list of json objects using variable `glpi_config_as_code_json`
|
||||||
|
|
||||||
|
example
|
||||||
|
|
||||||
|
``` yaml title="my_vars.yaml" linenums="1
|
||||||
|
glpi_config_as_code_json:
|
||||||
|
- "{{ lookup('file', '/workdir/files/glpi/ITILCategory-new-ldap-user.json') | from_json }}"
|
||||||
|
- "{{ lookup('file', '/workdir/files/glpi/LDAPAuth-local_ldap.json') | from_json }}"
|
||||||
|
|
||||||
|
```
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
title: Ansible Role nfc_glpi
|
title: nfc_glpi - Ansible Role
|
||||||
description: How to use No Fuss Computings Ansible role to manage GLPI from configuration as code.
|
description: How to use No Fuss Computings Ansible role to manage GLPI from configuration as code.
|
||||||
date: 2023-07-28
|
date: 2023-07-28
|
||||||
template: project.html
|
template: project.html
|
||||||
@ -13,6 +13,7 @@ This Ansible role is designed to manage GLPI specifically installation and confi
|
|||||||
|
|
||||||
- install GLPI using our [docker container](https://gitlab.com/nofusscomputing/projects/docker-glpi)
|
- install GLPI using our [docker container](https://gitlab.com/nofusscomputing/projects/docker-glpi)
|
||||||
|
|
||||||
|
- [Configure using Config from Code](config_from_code.md)
|
||||||
|
|
||||||
## Default Variables
|
## Default Variables
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ nav:
|
|||||||
|
|
||||||
- projects/nfc_glpi/index.md
|
- projects/nfc_glpi/index.md
|
||||||
|
|
||||||
|
- projects/nfc_glpi/config_from_code.md
|
||||||
|
|
||||||
- Operations:
|
- Operations:
|
||||||
|
|
||||||
- operations/index.md
|
- operations/index.md
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
when: glpi.api.session | default('') == ''
|
when: glpi.api.session | default('') == ''
|
||||||
|
|
||||||
|
|
||||||
|
- name: Append/Create Item
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: append-create-item.yaml
|
||||||
|
loop: "{{ glpi_config_as_code_json }}"
|
||||||
|
|
||||||
|
|
||||||
always:
|
always:
|
||||||
|
|
||||||
|
|
||||||
|
77
tasks/api/append-create-item.yaml
Normal file
77
tasks/api/append-create-item.yaml
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Create item_body
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
item_body: "{{ item.body }}"
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
|
||||||
|
- name: Search item_id
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: api/search/item_id.yaml
|
||||||
|
when: not item.body.id is defined
|
||||||
|
|
||||||
|
|
||||||
|
- name: Search entities_id
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: api/search/entities_id.yaml
|
||||||
|
when: item.entities_id is defined
|
||||||
|
|
||||||
|
|
||||||
|
- name: Search tickettemplates_id_demand
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: api/search/tickettemplates_id_demand.yaml
|
||||||
|
when: item.tickettemplates_id_demand is defined
|
||||||
|
|
||||||
|
|
||||||
|
- name: Search itilcategories_id
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: api/search/itilcategories_id.yaml
|
||||||
|
when: item.itilcategories_id is defined
|
||||||
|
|
||||||
|
|
||||||
|
- name: Search users_id
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: api/search/users_id.yaml
|
||||||
|
when: item.users_id is defined
|
||||||
|
|
||||||
|
|
||||||
|
- name: Show Body
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ item_body }}"
|
||||||
|
when: item_body is defined
|
||||||
|
|
||||||
|
|
||||||
|
- name: Create Item
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "http://{{ glpi.host }}/apirest.php/{{ item.api_path }}"
|
||||||
|
method: "POST"
|
||||||
|
return_content: true
|
||||||
|
body: "{\"input\": {{ item_body | from_yaml | to_json }} }"
|
||||||
|
status_code: [200, 201]
|
||||||
|
headers:
|
||||||
|
App-Token: "{{ glpi.app_token }}"
|
||||||
|
Session-Token: "{{ glpi.session.valid_id }}"
|
||||||
|
body_format: json
|
||||||
|
no_log: true
|
||||||
|
when: not item_body.id is defined
|
||||||
|
|
||||||
|
|
||||||
|
- name: Update Item
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "http://{{ glpi.host }}/apirest.php/{{ item.api_path }}/{{ item_body.id }}"
|
||||||
|
method: "PATCH"
|
||||||
|
return_content: true
|
||||||
|
body: "{\"input\": {{ item_body | from_yaml | to_json }} }"
|
||||||
|
status_code: [200, 201]
|
||||||
|
headers:
|
||||||
|
App-Token: "{{ glpi.app_token }}"
|
||||||
|
Session-Token: "{{ glpi.session.valid_id }}"
|
||||||
|
body_format: json
|
||||||
|
no_log: true
|
||||||
|
when: item_body.id is defined
|
||||||
|
|
||||||
|
|
||||||
|
- name: Clear temp vars
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
item_body: {}
|
Reference in New Issue
Block a user