diff options
| author | Ahmed Abdelhalim <[email protected]> | 2025-12-12 16:23:27 +0100 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2025-12-12 16:23:27 +0100 |
| commit | 1cc253f2da07ca33baf1ba6cac789cdb92923f36 (patch) | |
| tree | 723a8a743f6955d8c1949adec399827e7a0d7356 /roles/user/tasks | |
| parent | d0f7a25781c9aee4c61ba7bf5c7a3f26950f5737 (diff) | |
Update user role to allow configure a password instead of default
If no user_password is provided, the behavior remains the same, it uses
the default changeme password and requires to be changed for using sudo
If a user_password is provided, this hashed password will be used
instead of the default and doesn't require changing on first usage of
sudo
Diffstat (limited to 'roles/user/tasks')
| -rw-r--r-- | roles/user/tasks/main.yml | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/roles/user/tasks/main.yml b/roles/user/tasks/main.yml index 1177b707..bebedfcb 100644 --- a/roles/user/tasks/main.yml +++ b/roles/user/tasks/main.yml @@ -10,7 +10,7 @@ state: "present" loop: "{{ user_groups }}" -- name: "Create user: {{ username }}" +- name: "Create user with user_default_password" # noqa var-naming[no-role-prefix] username is more understandable than user_name become: true ansible.builtin.user: @@ -19,13 +19,29 @@ create_home: true generate_ssh_key: false groups: "{{ user_groups }}" - password: "{{ user_password }}" + password: "{{ user_default_password }}" shell: "/bin/bash" state: "present" update_password: "on_create" register: user notify: "Require password change" + when: not user_password is defined + +- name: "Create user with user_password" + # noqa var-naming[no-role-prefix] username is more understandable than user_name + become: true + ansible.builtin.user: + name: "{{ username }}" + append: true + create_home: true + generate_ssh_key: false + groups: "{{ user_groups }}" + password: "{{ user_password }}" + shell: "/bin/bash" + state: "present" + update_password: "on_create" no_log: true + when: user_password is defined - name: "Create user ssh directory" ansible.builtin.file: |
