ansible shell 转义单引号和双引号

sir*_*bax 4 shell quotes module escaping ansible

我正在尝试执行此命令:

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

蒙山ansible -m外壳模块(工作示例):

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

一种方法是将其放入文件中,但作为命令运行仍然很好 - 有什么想法吗?

Kon*_*rov 6

Bash 转义规则将执行以下操作:

ansible localhost -m shell -a "ps -eo pid,args --cols=10000 | awk '/\\/opt\\/logstash\\/logstash-1.5.3\\// && \$1 != PROCINFO[\"pid\"] { print \$1 }'"
Run Code Online (Sandbox Code Playgroud)