0

I am executing ansible adhoc command

ansible hosts -m shell -a 'df -P | awk '0+$5 >=30 {print}''
#ERROR! Missing target hosts

The single quotes that we use for awk print is conflicting with the -a '' command that we use.

I tried below formats no luck. I believe there is way to escape '

ansible hosts -m command -a 'df -P|awk '0+$5 >=30 {print}''
ansible hosts -m command -a "df -P|awk '0+$5 >=30 {print}'"
ansible hosts -m command -a 'df -P|awk "0+$5 >=30 {print}"'

Anyone has tried this before.

2
  • No luck, I tried all 3 perm/combo.
    – Siva
    Commented Jan 9, 2020 at 11:01
  • Is the group 'hosts' in your inventory? Do you have hosts defined? Keep in mind that the 'command' module is not going to work, you must use the shell for your command since you have a | pipe..
    – Zoredache
    Commented Jan 9, 2020 at 21:36

1 Answer 1

0

You can use " with awk and ' for -aoption, like below:

ansible hosts -m shell -a 'df -P | awk "0+$5 >=30 {print}"'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .