sirkubax sirkubax - 4 months ago 143
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

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 }'"