Ansible转义双引号和单引号

Geo*_*che 4 escaping double-quotes ansible single-quotes

我想用这个ansible命令在nrpe.cfg中插入一个nrpe命令

check_tomcat_threads.pl -H localhost -p 30011 -C '"http-bio-30011"' -w 200 -c 50
Run Code Online (Sandbox Code Playgroud)

但问题是"和"

要在nrpe.cfg中设置此行,请使用该命令

 - { regexp: '^command\[SERVICE_tomcat_pi_Threads\]', line: "command[SERVICE_tomcat_Threads_pi]=/appiu/monitoring/check_tomcat_threads.pl -H localhost -p 30011 -C '\"http-bio-30011\"' -w 200 -c 50" }
Run Code Online (Sandbox Code Playgroud)

但是nrpe.cfg中的结果是

...-C http-bio-30011..
Run Code Online (Sandbox Code Playgroud)

如果我在ansible脚本中使用''\"http-bio-30011 \"''

nrpe.cfg中的结果是

...-C "http-bio-30011"... 
Run Code Online (Sandbox Code Playgroud)

我如何逃避单引号和双引号来获得这个-C '"http-bio-30011"'

问候格奥尔格

Yar*_*min 5

这是一个错误lineinfile模块.

从YAML的角度来看,正确的语法如下(但只有在修复bug时才会起作用).你应该只转义两个字符"\双引文字:

line: "command[SERVICE_tomcat_Threads_pi]=/appiu/monitoring/check_tomcat_threads.pl -H localhost -p 30011 -C '\"http-bio-30011\"' -w 200 -c 50"
Run Code Online (Sandbox Code Playgroud)

要暂时解决它,您可以使用:

line: 'command[SERVICE_tomcat_Threads_pi]=/appiu/monitoring/check_tomcat_threads.pl -H localhost -p 30011 -C \''"http-bio-30011"\'' -w 200 -c 50'
Run Code Online (Sandbox Code Playgroud)