gpt4 book ai didi

escaping - Ansible转义双引号和单引号

转载 作者:行者123 更新时间:2023-12-05 00:58:17 26 4
gpt4 key购买 nike

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

check_tomcat_threads.pl -H localhost -p 30011 -C '"http-bio-30011"' -w 200 -c 50

但问题是 '"和 "'

要在 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" }

但 nrpe.cfg 中的结果是
...-C http-bio-30011..

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

nrpe.cfg 中的结果是
...-C "http-bio-30011"... 

我如何转义单引号和双引号来得到这个 -C '"http-bio-30011"' ?

问候乔治

最佳答案

这是一个 buglineinfile模块。

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

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

要临时解决它,您可以使用:
line: 'command[SERVICE_tomcat_Threads_pi]=/appiu/monitoring/check_tomcat_threads.pl -H localhost -p 30011 -C \''"http-bio-30011"\'' -w 200 -c 50'

关于escaping - Ansible转义双引号和单引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32992573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com