feat(ansible-role-remote_users_fact) first commit

This commit is contained in:
2026-04-13 23:25:51 +02:00
commit 51f19b678f
11 changed files with 478 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
---
# =============================================================================
# tasks/deploy.yml — Création du répertoire et copie du fact
# =============================================================================
- name: Créer le répertoire facts.d
ansible.builtin.file:
path: "{{ remote_users_fact_dir }}"
state: directory
owner: "{{ remote_users_fact_owner }}"
group: "{{ remote_users_fact_group }}"
mode: "0755"
- name: Déployer le script remote_users.fact
ansible.builtin.copy:
src: "{{ remote_users_fact_name }}"
dest: "{{ remote_users_fact_dir }}/{{ remote_users_fact_name }}"
owner: "{{ remote_users_fact_owner }}"
group: "{{ remote_users_fact_group }}"
mode: "0755"
backup: true
register: _remote_users_fact_deployed
notify: Recharger les local facts
+24
View File
@@ -0,0 +1,24 @@
---
# =============================================================================
# tasks/main.yml — Déploiement et validation du local fact remote_users
# =============================================================================
- name: Inclure les tâches de déploiement
ansible.builtin.include_tasks: deploy.yml
tags:
- remote_users_fact
- deploy
- name: Inclure les tâches de validation
ansible.builtin.include_tasks: validate.yml
when: remote_users_fact_validate | bool
tags:
- remote_users_fact
- validate
- name: Inclure les tâches de résumé
ansible.builtin.include_tasks: summary.yml
when: remote_users_fact_display_summary | bool
tags:
- remote_users_fact
- summary
+34
View File
@@ -0,0 +1,34 @@
---
# =============================================================================
# tasks/summary.yml — Affichage du résumé et alertes éventuelles
# =============================================================================
- name: Afficher le résumé des sessions distantes
ansible.builtin.debug:
msg:
- "══════════════════════════════════════════"
- "Host : {{ inventory_hostname }}"
- "Timestamp : {{ ansible_local.remote_users.timestamp }}"
- "──────────────────────────────────────────"
- "SSH : {{ ansible_local.remote_users.sessions.ssh }}"
- "Citrix : {{ ansible_local.remote_users.sessions.citrix }}"
- "Horizon : {{ ansible_local.remote_users.sessions.horizon }}"
- "Total proto : {{ ansible_local.remote_users.sessions.total_by_protocol }}"
- "Who remote : {{ ansible_local.remote_users.sessions.who_remote }}"
- "──────────────────────────────────────────"
- "Verdict : {{ ansible_local.remote_users.reliability.verdict }}"
- "Ratio : {{ ansible_local.remote_users.reliability.ratio_who_over_total }}"
- "Détail : {{ ansible_local.remote_users.reliability.detail }}"
- "──────────────────────────────────────────"
- "Utilisateurs: {{ ansible_local.remote_users.users_remote | default('aucun') }}"
- "Citrix VDA : {{ ansible_local.remote_users.detection.citrix_vda_installed }}"
- "Horizon Agt : {{ ansible_local.remote_users.detection.horizon_agent_installed }}"
- "══════════════════════════════════════════"
- name: Alerter si le verdict est anormal
ansible.builtin.debug:
msg: >-
⚠ ATTENTION sur {{ inventory_hostname }} —
Verdict: {{ ansible_local.remote_users.reliability.verdict }} —
{{ ansible_local.remote_users.reliability.detail }}
when: ansible_local.remote_users.reliability.verdict in remote_users_fact_warn_verdicts
@@ -0,0 +1,37 @@
---
# =============================================================================
# tasks/validate.yml — Validation du fact (exécution + parsing JSON)
# =============================================================================
- name: Forcer le rechargement des facts si déploiement effectué
ansible.builtin.meta: flush_handlers
- name: Exécuter le script fact manuellement pour validation
ansible.builtin.command:
cmd: "{{ remote_users_fact_dir }}/{{ remote_users_fact_name }}"
register: _remote_users_fact_output
changed_when: false
failed_when: _remote_users_fact_output.rc != 0
- name: Valider que la sortie est du JSON parsable
ansible.builtin.set_fact:
_remote_users_fact_parsed: "{{ _remote_users_fact_output.stdout | from_json }}"
- name: Vérifier la présence des clés obligatoires
ansible.builtin.assert:
that:
- _remote_users_fact_parsed.sessions is defined
- _remote_users_fact_parsed.sessions.ssh is defined
- _remote_users_fact_parsed.sessions.citrix is defined
- _remote_users_fact_parsed.sessions.horizon is defined
- _remote_users_fact_parsed.sessions.total_by_protocol is defined
- _remote_users_fact_parsed.sessions.who_remote is defined
- _remote_users_fact_parsed.reliability is defined
- _remote_users_fact_parsed.reliability.verdict is defined
- _remote_users_fact_parsed.detection is defined
fail_msg: "Le fact remote_users ne retourne pas la structure JSON attendue"
success_msg: "Structure JSON validée avec succès"
- name: Recharger les ansible_local facts
ansible.builtin.setup:
filter: ansible_local