Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 437
sirkubax Avatar asked Mar 11 '23 15:03

sirkubax


2 Answers

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 }'"
like image 109
Konstantin Suvorov Avatar answered Mar 20 '23 03:03

Konstantin Suvorov


Mine alternative version that worked:

ansible -m command -a "ps a |grep -E '/opt/logstash/logstash-1.5.3/vendor/jruby' " all --sudo

Check if the process are running:

ansible -m shell -a "ps aux |grep -E '/opt/logstash/logstash-1.5.3/vendor/jruby'|grep -v -e grep |wc" all 
like image 20
sirkubax Avatar answered Mar 20 '23 04:03

sirkubax