ansible批量跑出所有用户的定时计划任务
[root@libin3]# cat libin.yml
- hosts: task gather_facts: no tasks: - name: fetch shell: | for i in `awk -F':' '{if( $3>=0 )print $1 }' /etc/passwd `;do ([[ `crontab -u $i -l 2>&1 |grep -Ev '^no|^$' |wc -l` == 0 ]]&&(echo "$i;no_crontab") ||(echo "$i"&&crontab -u $i -l|grep -v '^#'))|sed ":a;N;s/\n/;/g;ta"|sed -r 's/[ ]+/+/g';done | awk '{print "{{ inventory_hostname }}",$0}' register: serial - name: dd shell: | echo "{{serial.stdout}},{{inventory_hostname}}" >> libin.csv delegate_to: localhost

浙公网安备 33010602011771号