Skip to content
Snippets Groups Projects
Commit 8fe4cd93 authored by Jürgen Haas's avatar Jürgen Haas
Browse files

Remove the dependency on perl

parent 9d229d0c
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
echo "[" >/etc/ansible/facts.d/users.fact
cat /etc/passwd | perl -aF: -ne 'print "{\"name\": \"",$F[0],"\",\"home\": \"",$F[5],"\"},\n" if $F[2] > 499' >>/etc/ansible/facts.d/users.fact
echo "0]" >>/etc/ansible/facts.d/users.fact
......@@ -5,31 +5,24 @@
---
# file: cleanup.yml
- name: "Make sure, the directory exists"
file: dest='/etc/ansible/facts.d'
state=directory
owner=root
group=root
mode=775
- name: "Copy the extract script"
copy: src='etc_ansible_facts_d_users_sh'
dest='/etc/ansible/facts.d/users.sh'
owner=root
group=root
mode=755
- name: "Extract user list"
shell: /etc/ansible/facts.d/users.sh
- name: "Gather facts"
setup:
- name: "Grab the user list"
shell: cat /etc/passwd
register: passwd
- name: "Unlock legitimate user accounts"
command: usermod --unlock {{item.name}}
with_items: ansible_local.users
when: item.name is defined and item.name in users
command: usermod --unlock {{item.split(':').0}}
when: item.split(':').0 in users
and item.split(':').2|int > 499
with_items: passwd.stdout_lines
- name: "Lock deprecated user accounts"
command: usermod --lock {{item.name}}
with_items: ansible_local.users
when: item.name is defined and item.name not in users
command: usermod --lock {{item.split(':').0}}
when: item.split(':').0 not in users
and item.split(':').2|int > 499
with_items: passwd.stdout_lines
- name: "Disable ssh keys for deprecated user accounts"
command: rm {{item.home}}/.ssh/authorized_keys
with_items: ansible_local.users
when: item.name is defined and item.name not in users
command: rm {{item.split(':').5}}/.ssh/authorized_keys
when: item.split(':').0 not in users
and item.split(':').2|int > 499
with_items: passwd.stdout_lines
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment