diff --git a/image-builder/assets/playbooks/roles/osconfig/defaults/main.yaml b/image-builder/assets/playbooks/roles/osconfig/defaults/main.yaml index 326dd82..8079c6c 100644 --- a/image-builder/assets/playbooks/roles/osconfig/defaults/main.yaml +++ b/image-builder/assets/playbooks/roles/osconfig/defaults/main.yaml @@ -226,6 +226,16 @@ file_permissions: # combined with previous item) run_contexts: - "{{ default_run_context }}" +# Set password and login shell for existing users +# Mainly intended to lock down system users +# Will not create user if does not exist +user_management: + - name: test + shell: /usr/sbin/nologin + password: '!' + password_lock: yes + run_contexts: + - "{{ default_run_context }}" # If any required resources need to be fetched from URL for image build customization, they can be added here. # Downloaded resources can be found in /tmp/url_resources directory. # Example:- diff --git a/image-builder/assets/playbooks/roles/osconfig/tasks/main.yaml b/image-builder/assets/playbooks/roles/osconfig/tasks/main.yaml index 2ed6c66..483ea40 100644 --- a/image-builder/assets/playbooks/roles/osconfig/tasks/main.yaml +++ b/image-builder/assets/playbooks/roles/osconfig/tasks/main.yaml @@ -59,6 +59,8 @@ include_tasks: user-scripts.yaml - name: "configure file permissions" include_tasks: file-permissions.yaml +- name: "configure user password settings" + include_tasks: user-management.yaml # Context-independent cleanup tasks - name: "finalize rootfs" diff --git a/image-builder/assets/playbooks/roles/osconfig/tasks/user-management.yaml b/image-builder/assets/playbooks/roles/osconfig/tasks/user-management.yaml new file mode 100644 index 0000000..c0bc479 --- /dev/null +++ b/image-builder/assets/playbooks/roles/osconfig/tasks/user-management.yaml @@ -0,0 +1,12 @@ +- name: "Get all account info" + getent: + database: passwd + +- name: "User Management | Modifying user settings for {{ item.name }}" + user: + name: "{{ item.name }}" + password: "{{ item.password }}" + password_lock: "{{ item.password_lock }}" + shell: "{{ item.shell }}" + loop: "{{ user_management }}" + when: run_context in item.run_contexts and item.name in ansible_facts.getent_passwd \ No newline at end of file