-
Notifications
You must be signed in to change notification settings - Fork 10
/
ldap_ban.yml
85 lines (73 loc) · 2.24 KB
/
ldap_ban.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- eval: (ansible) -*-
- include: vault.yml load=ldap hosts=ldap.hashbang.sh
- name: Parse parameters
hosts: ldap.hashbang.sh,shell_servers
gather_facts: no
vars_prompt:
- name: users
prompt: Comma-separated list of users to ban
private: no
- name: delete_home
prompt: Delete home directories? (yes/no)
private: no
default: "no"
- name: delete_ssh
prompt: Delete SSH keys in LDAP? (yes/no)
private: no
default: "no"
tasks:
- name: Parse users list
set_fact:
user_list: "{{ users.split(',') }}"
delete_homedirs: "{{ delete_home }}"
delete_ssh_keys: "{{ delete_ssh }}"
- name: Update LDAP directory
hosts: ldap.hashbang.sh
gather_facts: no
tasks:
- name: Disable the account (shell set to nologin)
delegate_to: localhost
with_items: "{{ user_list }}"
ldap_attr:
server_uri: ldaps://ldap.hashbang.sh
bind_dn: "{{ ldap.admin.dn }}"
bind_pw: "{{ ldap.admin.password }}"
dn: uid={{ item }},ou=People,dc=hashbang,dc=sh
name: loginShell
state: exact
values: /usr/sbin/nologin
- name: Remove SSH keys
delegate_to: localhost
with_items: "{{ user_list }}"
when: delete_ssh_keys
ldap_attr:
server_uri: ldaps://ldap.hashbang.sh
bind_dn: "{{ ldap.admin.dn }}"
bind_pw: "{{ ldap.admin.password }}"
dn: uid={{ item }},ou=People,dc=hashbang,dc=sh
name: sshPublicKey
state: exact
values: ""
- hosts: shell_servers
become: true
gather_facts: no
tasks:
- name: Invalidate SSSd cache entries
command: sss_cache -u {{ item }}
with_items: "{{ user_list }}"
changed_when: false
ignore_errors: yes
- name: Terminate user sessions
command: loginctl terminate-user {{ item }}
register: terminate
with_items: "{{ user_list }}"
failed_when: |
'Could not terminate user: No user' not in terminate.stderr
and terminate is failed
changed_when: terminate.stderr and terminate is success
- name: Delete home directories
when: delete_homedirs
with_items: "{{ user_list }}"
file:
path: /home/{{ item }}
state: absent