105 lines
3.3 KiB
Markdown
105 lines
3.3 KiB
Markdown
|
|
# remote_users_fact
|
||
|
|
|
||
|
|
Rôle Ansible qui déploie un **local fact** comptant les sessions distantes par protocole (SSH, Citrix, Horizon) et évaluant la fiabilité en comparant avec `who`.
|
||
|
|
|
||
|
|
## Arborescence
|
||
|
|
|
||
|
|
```
|
||
|
|
├── site.yml # Playbook principal
|
||
|
|
├── inventories/
|
||
|
|
│ └── hosts.yml # Inventaire exemple
|
||
|
|
└── roles/
|
||
|
|
└── remote_users_fact/
|
||
|
|
├── defaults/main.yml # Variables par défaut
|
||
|
|
├── files/remote_users.fact # Script fact déployé
|
||
|
|
├── handlers/main.yml # Handler rechargement facts
|
||
|
|
├── meta/main.yml # Métadonnées Galaxy
|
||
|
|
└── tasks/
|
||
|
|
├── main.yml # Orchestration
|
||
|
|
├── deploy.yml # Création répertoire + copie
|
||
|
|
├── validate.yml # Exécution + parsing JSON
|
||
|
|
└── summary.yml # Affichage résumé + alertes
|
||
|
|
```
|
||
|
|
|
||
|
|
## Usage
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Déploiement complet
|
||
|
|
ansible-playbook -i inventories/hosts.yml site.yml
|
||
|
|
|
||
|
|
# Déploiement seul
|
||
|
|
ansible-playbook -i inventories/hosts.yml site.yml --tags deploy
|
||
|
|
|
||
|
|
# Vérification seule (fact déjà déployé)
|
||
|
|
ansible-playbook -i inventories/hosts.yml site.yml --tags validate,summary
|
||
|
|
|
||
|
|
# Sur un groupe spécifique
|
||
|
|
ansible-playbook -i inventories/hosts.yml site.yml -l citrix_servers
|
||
|
|
```
|
||
|
|
|
||
|
|
## Variables
|
||
|
|
|
||
|
|
| Variable | Défaut | Description |
|
||
|
|
|---|---|---|
|
||
|
|
| `remote_users_fact_dir` | `/etc/ansible/facts.d` | Répertoire de destination |
|
||
|
|
| `remote_users_fact_name` | `remote_users.fact` | Nom du script |
|
||
|
|
| `remote_users_fact_owner` | `root` | Propriétaire |
|
||
|
|
| `remote_users_fact_group` | `root` | Groupe |
|
||
|
|
| `remote_users_fact_validate` | `true` | Activer la validation post-deploy |
|
||
|
|
| `remote_users_fact_display_summary` | `true` | Afficher le résumé |
|
||
|
|
| `remote_users_fact_warn_verdicts` | voir defaults | Verdicts déclenchant un warning |
|
||
|
|
|
||
|
|
## Fact déployé
|
||
|
|
|
||
|
|
Accessible via `ansible_local.remote_users` :
|
||
|
|
|
||
|
|
```json
|
||
|
|
{
|
||
|
|
"timestamp": "2026-04-13T10:30:00Z",
|
||
|
|
"sessions": {
|
||
|
|
"ssh": 3,
|
||
|
|
"citrix": 12,
|
||
|
|
"horizon": 0,
|
||
|
|
"total_by_protocol": 15,
|
||
|
|
"who_remote": 14
|
||
|
|
},
|
||
|
|
"users_remote": "alice,bob,charlie",
|
||
|
|
"reliability": {
|
||
|
|
"ratio_who_over_total": 0.93,
|
||
|
|
"verdict": "WHO_INF_TOTAL",
|
||
|
|
"detail": "who manque 1 session(s) sans TTY"
|
||
|
|
},
|
||
|
|
"detection": {
|
||
|
|
"citrix_vda_installed": true,
|
||
|
|
"horizon_agent_installed": false,
|
||
|
|
"ssh_method": "sshd_process_and_ss",
|
||
|
|
"citrix_method": "ctxquery",
|
||
|
|
"horizon_method": "fallback_ports"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
## Verdicts
|
||
|
|
|
||
|
|
| Verdict | Signification |
|
||
|
|
|---|---|
|
||
|
|
| `FIABLE` | who == total → compteurs alignés |
|
||
|
|
| `OK` | Écart ≤ 1 → tolérable |
|
||
|
|
| `WHO_SUP_TOTAL` | who > total → protocole non surveillé |
|
||
|
|
| `WHO_INF_TOTAL` | who < total → sessions headless sans TTY |
|
||
|
|
| `WHO_SEUL` | total == 0 → protocoles non détectés |
|
||
|
|
| `PROTO_SEUL` | who == 0 → sessions sans allocation TTY |
|
||
|
|
| `NEUTRE` | 0 == 0 → aucune session |
|
||
|
|
|
||
|
|
## Utilisation dans d'autres playbooks
|
||
|
|
|
||
|
|
```yaml
|
||
|
|
- hosts: all
|
||
|
|
gather_facts: true
|
||
|
|
tasks:
|
||
|
|
- name: Refuser un déploiement si trop de sessions actives
|
||
|
|
ansible.builtin.fail:
|
||
|
|
msg: "{{ ansible_local.remote_users.sessions.total_by_protocol }} sessions actives, déploiement annulé"
|
||
|
|
when: ansible_local.remote_users.sessions.total_by_protocol | int > 10
|
||
|
|
```
|