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
posted @ 2023-03-20 15:05  LB_运维技术  阅读(52)  评论(0编辑  收藏  举报