From b9a9f858bdcc1e572a96ff2c62f25966eb08a612 Mon Sep 17 00:00:00 2001 From: Ryan Hamilton Date: Wed, 18 Jun 2025 14:55:24 -0500 Subject: [PATCH] add playbook to check user group membership --- playbooks/checkforsshusers.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 playbooks/checkforsshusers.yml diff --git a/playbooks/checkforsshusers.yml b/playbooks/checkforsshusers.yml new file mode 100644 index 0000000..5fc89c6 --- /dev/null +++ b/playbooks/checkforsshusers.yml @@ -0,0 +1,31 @@ +--- +- name: Check if user is in specified group + hosts: all + gather_facts: false + become: true + + vars_prompt: + - name: check_user + prompt: "Enter the username to check" + private: no + + - name: check_group + prompt: "Enter the group to verify membership" + private: no + + tasks: + - name: Get groups for specified user + ansible.builtin.command: "id -nG {{ check_user }}" + register: user_groups + changed_when: false + failed_when: user_groups.rc != 0 + + - name: Set fact if user is in group + set_fact: + user_in_group: "{{ check_group in user_groups.stdout.split() }}" + + - name: Report user group membership + debug: + msg: > + User '{{ check_user }}' {{ 'IS' if user_in_group else 'IS NOT' }} + in the '{{ check_group }}' group on {{ inventory_hostname }}.