From 1a2afbb3f85f3a39e35ff24a8a22147105596668 Mon Sep 17 00:00:00 2001 From: "pulsar89.5" Date: Tue, 23 May 2023 12:11:36 +0200 Subject: [PATCH] =?UTF-8?q?[EVO]=20G=C3=A9n=C3=A9rer=20dynamiquement=20la?= =?UTF-8?q?=20liste=20des=20utilisateurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++-- defaults/main.yml | 13 +++++++++++++ tasks/installation.yml | 10 +++++++++- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3edfbf7..d42ecd8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,43 @@ -# role_modele +# role_users -Modèle \ No newline at end of file +Ce rôle permet de créer et configurer des utilisateurs systèmes. + +## Variables + +### users_* + +Liste contenant la configuration des utilisateurs. + +*Valeur par défaut: 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 +``` diff --git a/defaults/main.yml b/defaults/main.yml index 5f42ede..2d12759 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 diff --git a/tasks/installation.yml b/tasks/installation.yml index 3435f74..1a28637 100644 --- a/tasks/installation.yml +++ b/tasks/installation.yml @@ -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: