[EVO] Générer dynamiquement la liste des utilisateurs
This commit is contained in:
parent
1d4aaf909e
commit
1a2afbb3f8
44
README.md
44
README.md
@ -1,3 +1,43 @@
|
||||
# role_modele
|
||||
# role_users
|
||||
|
||||
Modèle
|
||||
Ce rôle permet de créer et configurer des utilisateurs systèmes.
|
||||
|
||||
## Variables
|
||||
|
||||
### users_*
|
||||
|
||||
Liste contenant la configuration des utilisateurs.
|
||||
|
||||
*<span style="text-decoration: underline">Valeur par défaut:</span> aucune*
|
||||
|
||||
## Exemple d'utilisation
|
||||
|
||||
### inventory.yml
|
||||
|
||||
```yaml
|
||||
---
|
||||
|
||||
all:
|
||||
hosts:
|
||||
host1.ykn.local:
|
||||
```
|
||||
|
||||
### host_vars/host1.ykn.local.yml
|
||||
|
||||
```yaml
|
||||
---
|
||||
|
||||
users: []
|
||||
- name: ansible
|
||||
comment: "Ansible user"
|
||||
update_password: on_create
|
||||
password_lock: true
|
||||
append: true
|
||||
shell: /bin/bash
|
||||
groups: ["sudo"]
|
||||
extras:
|
||||
authorized_keys:
|
||||
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILNxxMmKSUHibYrlwyhx6UzyEAIPrghuQ/2fiCvcGAfh ansible
|
||||
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJPerG1LAvNuuwuMnlExCyfsRwGqrM1U3C/aUtuXqhyu bot_ansible
|
||||
sudoers: ansible ALL=(ALL) NOPASSWD:AL
|
||||
```
|
||||
|
@ -2,3 +2,16 @@
|
||||
# defaults file for users
|
||||
|
||||
users: []
|
||||
#Exemple:
|
||||
# - name: ansible
|
||||
# comment: "Ansible user"
|
||||
# update_password: on_create
|
||||
# password_lock: true
|
||||
# append: true
|
||||
# shell: /bin/bash
|
||||
# groups: ["sudo"]
|
||||
# extras:
|
||||
# authorized_keys:
|
||||
# - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILNxxMmKSUHibYrlwyhx6UzyEAIPrghuQ/2fiCvcGAfh ansible
|
||||
# - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJPerG1LAvNuuwuMnlExCyfsRwGqrM1U3C/aUtuXqhyu bot_ansible
|
||||
# sudoers: ansible ALL=(ALL) NOPASSWD:ALL
|
||||
|
@ -1,6 +1,14 @@
|
||||
---
|
||||
# tasks file for users
|
||||
|
||||
- name: Construire la liste des utilisateurs
|
||||
ansible.builtin.set_fact:
|
||||
users: "{{ users + specific }}"
|
||||
when: specific | length > 0
|
||||
loop: "{{ lookup('ansible.builtin.varnames', '^users.+', wantlist=True) }}"
|
||||
vars:
|
||||
specific: "{{ lookup('ansible.builtin.vars', item, default='') }}"
|
||||
|
||||
- name: Créer un groupe au nom de l'utilisateur
|
||||
ansible.builtin.group:
|
||||
name: "{{ item.name }}"
|
||||
@ -16,7 +24,7 @@
|
||||
become: true
|
||||
loop: "{{ users | subelements('groups', skip_missing=True) }}"
|
||||
loop_control:
|
||||
label: "{{ item.0.name }} to {{ item.1 }}"
|
||||
label: "{{ item.1 }}"
|
||||
|
||||
- name: Créer les utilisateurs
|
||||
ansible.builtin.user:
|
||||
|
Loading…
Reference in New Issue
Block a user