diff --git a/tasks/prune.yml b/tasks/prune.yml index 56e4e7fc9a7a52b736c0b705c5805e019a80941f..1c9f8045bd723ed68aca85bf446e3590523c5ade 100644 --- a/tasks/prune.yml +++ b/tasks/prune.yml @@ -10,9 +10,13 @@ command: whoami register: users_whoami +- name: Get the nobody uid + command: id -u nobody + register: users_nobody_uid + - name: Prune users - with_items: '{{ getent_passwd|difference(users_unique_names) }}' - when: getent_passwd[item][2]|int > 999 and getent_passwd[item][2]|int != 65534 and item != users_whoami.stdout.strip() + with_items: '{{ getent_passwd|difference(users_unique_names)|difference(["nobody", users_whoami.stdout.strip()]) }}' + when: getent_passwd[item][2]|int > 999 and getent_passwd[item][2] != users_nobody_uid.stdout.strip() # Actual, non-system users. user: name: '{{ item }}' state: absent