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 @@ ...@@ -5,31 +5,24 @@
--- ---
# file: cleanup.yml # file: cleanup.yml
- name: "Make sure, the directory exists" - name: "Grab the user list"
file: dest='/etc/ansible/facts.d' shell: cat /etc/passwd
state=directory register: passwd
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: "Unlock legitimate user accounts" - name: "Unlock legitimate user accounts"
command: usermod --unlock {{item.name}} command: usermod --unlock {{item.split(':').0}}
with_items: ansible_local.users when: item.split(':').0 in users
when: item.name is defined and item.name in users and item.split(':').2|int > 499
with_items: passwd.stdout_lines
- name: "Lock deprecated user accounts" - name: "Lock deprecated user accounts"
command: usermod --lock {{item.name}} command: usermod --lock {{item.split(':').0}}
with_items: ansible_local.users when: item.split(':').0 not in users
when: item.name is defined and item.name not in users and item.split(':').2|int > 499
with_items: passwd.stdout_lines
- name: "Disable ssh keys for deprecated user accounts" - name: "Disable ssh keys for deprecated user accounts"
command: rm {{item.home}}/.ssh/authorized_keys command: rm {{item.split(':').5}}/.ssh/authorized_keys
with_items: ansible_local.users when: item.split(':').0 not in users
when: item.name is defined and item.name 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.
Please register or to comment