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: