jumpserver/apps/accounts/automations/gather_accounts/host/posix/main.yml

21 lines
591 B
YAML
Raw Normal View History

2022-10-27 10:53:10 +00:00
- hosts: demo
gather_facts: no
tasks:
- name: Gather posix account
2022-10-28 10:28:41 +00:00
ansible.builtin.shell:
cmd: >
users=$(getent passwd | grep -v nologin | grep -v shutdown | awk -F":" '{ print $1 }');for i in $users;
do k=$(last -w -F $i -1 | head -1 | grep -v ^$ | awk '{ print $0 }')
if [ -n "$k" ]; then
echo $k
else
echo $i
fi;done
2022-10-27 10:53:10 +00:00
register: result
- name: Define info by set_fact
ansible.builtin.set_fact:
info: "{{ result.stdout_lines }}"
- debug:
var: info