ansible 基础巡检

1.通过ansible 每天对线上的机器磁盘、内存、负载进行巡检

 

 

[root@BS003 probject]# cat cpu.yaml 

- name: Statistics CPU Memory Disk Utilization

  hosts: zabbix-agent

  tasks:

  become: no

  remote_user: "{{ user }}"

  gather_facts: no

  tasks:

    - name: "Statistics CPU Memory Disk Utilization..."

      shell: |

        free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'

        df -h -t ext2 -t ext4 | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print "Disk Usage:"" " $1 " " $3"/"$2" ""("$5")"}'

        top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}'

      register: out

    - debug: var=out.stdout_lines

[root@BS003 probject]# 

posted @ 2020-06-05 10:23  地铁昌平线  阅读(1217)  评论(0编辑  收藏  举报