init commit
This commit is contained in:
31
playbooks/check-useringroup.yml
Normal file
31
playbooks/check-useringroup.yml
Normal file
@@ -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 }}.
|
Reference in New Issue
Block a user