From 7c91db950b4a49d5387e8004ec989dd188e88ab8 Mon Sep 17 00:00:00 2001 From: Tyler Hale Date: Tue, 1 Apr 2025 09:15:24 -0600 Subject: [PATCH] Adding user state management --- roles/base/defaults/main.yml | 1 + roles/base/tasks/core_users.yml | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/roles/base/defaults/main.yml b/roles/base/defaults/main.yml index 0eb5146..43a8c62 100644 --- a/roles/base/defaults/main.yml +++ b/roles/base/defaults/main.yml @@ -17,6 +17,7 @@ base_users: [] # ssh_keys_force: false # setting ssh_keys_force to true will overwrite the authorized_keys file to only be the ssh keys provided # groups: [] # groups_append: true +# state: present # Install all available updates at runtime base_core_install_updates: true diff --git a/roles/base/tasks/core_users.yml b/roles/base/tasks/core_users.yml index 025b3dc..2292490 100644 --- a/roles/base/tasks/core_users.yml +++ b/roles/base/tasks/core_users.yml @@ -4,11 +4,14 @@ - name: "{{ user.username }} user setup" user: name: "{{ user.username }}" + state: "{{ user.state | default('present') }}" + force: true password_lock: "{{ user.disable_password | default(false) }}" - name: "{{ user.username }} group setup" user: name: "{{ user.username }}" + state: "{{ user.state | default('present') }}" groups: "{{ user.groups | join(',') }}" append: "{{ user.groups_append | default('true') }}" when: user.groups is defined @@ -16,13 +19,14 @@ - name: "Configure {{ user.username }} password" user: name: "{{ user.username }}" + state: "{{ user.state | default('present') }}" password: "{{ user.password | default('*') }}" when: user.password is defined - name: "Setup {{ user.username }} authorized keys" authorized_key: user: "{{ user.username }}" - state: present + state: "{{ user.state | default('present') }}" key: "{{ user.ssh_keys | join('\n') }}" exclusive: "{{ user.ssh_keys_force | default('false') }}" tags: @@ -32,7 +36,7 @@ - name: "Setup {{ user.username }} authorized keys from url" authorized_key: user: "{{ user.username }}" - state: present + state: "{{ user.state | default('present') }}" key: "{{ user.ssh_keys }}" exclusive: "{{ user.ssh_keys_force | default('false') }}" tags: