本文介绍了ansible lineinfile 中的引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 ansible 中使用 lineinfile 时,它不会写入 ', " 字符lineinfile: 'dest=/home/xyz state=present line="CACHES="default""'

When I use lineinfile in ansible it is not writing ', " characterslineinfile: 'dest=/home/xyz state=present line="CACHES="default""'

它给出了 CACHES=default但所需的输出是 CACHES="default"

it is giving CACHES=defaultbut the desired output is CACHES="default"

如何实现这一目标?

推荐答案

看来你可以转义引号了:

it appears you can escape the quotes:

- lineinfile: dest=/tmp/xyz state=present line="CACHES=\"default\""

这给出了这个输出:

$ cat /tmp/xyz
CACHES="default"

您不需要转义双引号内的单引号:

You don't need to escape single quotes that are inside double quotes:

- lineinfile: dest=/tmp/xyz state=present line="CACHES=\"default\" foo='x'"
cat /tmp/xyz
CACHES="default" foo='x'

来源:YAML 规范stackoverflow 答案

这篇关于ansible lineinfile 中的引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 05:48