---
#
# Secrets in "/{{ site_name }}":
#
# Anything starting "glpi_" will be propagated to the confiugration.
#
# Expected secrets:
#
# * glpi_local (for debugging)
# * glpi_server (for remote assets management integration)
# * glpi_user
# * glpi_password
# * glpi_tag
#
- name: GLPI Agent Configuration
  hosts: allnodes
  become: true
  tasks:
    - name: Get Secrets From Vault
      set_fact:
        secret: "{{ lookup('community.hashi_vault.hashi_vault', vault_mount_point + '/site-' + site_name, token_validate=false) }}"
    - name: Debug Secrets
      debug:
        msg: "{{ item.key }} = {{ item.value }}"
      loop: "{{ secret | dict2items }}"
    - name: Directory for for GLPI agent configuration
      file:
        path: /etc/glpi-agent/conf.d
        state: directory
        mode: 0755
    - name: Configuration For GLPI Agent
      template:
        src: "templates/{{ item }}.j2"
        dest: "{{ item }}"
        mode: 0600
      loop:
        - /etc/glpi-agent/conf.d/01-eosc.cfg
      notify: Reload GLPI Agent
  handlers:
    - name: Reload GLPI Agent
      service:
        name: glpi-agent
        state: reloaded

- name: GLPI Agent Deployment
  hosts: allnodes
  roles:
    - role: 'ipr-cnrs.glpi_agent'
      vars:
        glpi_agent__install_from_url: true
        glpi_agent__version: '1.10-1'
