sirkubax sirkubax - 1 year ago 566
Bash Question

ansible shell escape single and double quotes

I'm trying to execute this command:

ps -eo pid,args --cols=10000 | awk '/\/opt\/logstash\/logstash-1.5.3\// && $1 != PROCINFO["pid"] { print $1 }'

whith ansible -m shell module (not working example):

ansible -m shell -a '"'ps -eo pid,args --cols=10000 | awk '/\/opt\/logstash\/logstash-1.5.3\// && $1 != PROCINFO[\'pid\'] { print $1 }' '"' all

One of the ways would be to put that into a file, but still it would be nice to run as a command - any ideas?

Answer Source

Bash escaping rules will do:

ansible localhost -m shell -a "ps -eo pid,args --cols=10000 | awk '/\\/opt\\/logstash\\/logstash-1.5.3\\// && \$1 != PROCINFO[\"pid\"] { print \$1 }'"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download