简体   繁体   中英

check mount point usage using ansible

I am trying to list the mount point that are used more than 50% using ansible. I am getting error on AWK.

If I run this command individually it works

df -P | awk '$5 >=90 {print}'
Filesystem     1024-blocks     Used Available Capacity Mounted on
tmpfs              2097152  1948868    148284      93% /tmp

or

df -P | grep /tmp | awk '$5 >=90 {print}'
tmpfs              2097152  1948832    148320      93% /tmp

If I put the same command in ansible shell it fails

Here:

ansible all -i <hostname>, -m shell -a "df -P | grep /tmp | awk '$5 >=90 {print}'"
SSH password:
SUDO password[defaults to SSH password]:
<hostname> | FAILED | rc=1 >>
awk:  >=90 {print}
awk:  ^ syntax error
grep: write error: Broken pipe

Is there a way to do this? Is there a better way to do this? may be using the factors?

Thanks Konstantin Suvorov your answer worked perfectly.

ansible all -i <hostname>, -m shell -a "df -P | grep /tmp | awk '\$5 >=50 {print}'"
SSH password:
SUDO password[defaults to SSH password]:
<hostname> | SUCCESS | rc=0 >>
/dev/sda8           944808      55484     840496       7% /var/tmp
tmpfs              2097152    1858344     238808      89% /tmp

@ user3330284:您可以删除grep的使用并尝试以下操作(尽管未测试):

ansible all -i <hostname>, -m shell -a "df -P  | awk '/\/tmp/{if(\$5 >=50){print}}'"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM