Ansible set_fact 的 No 值转换为 False [英] Ansible set_fact value of No converted into False
本文介绍了Ansible set_fact 的 No 值转换为 False的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用 set_fact
时遇到了一个烦人的问题,我设置了一个值为 No
的 var,但是一旦我调用 var ansible 将其转换为 False代码> 有办法解决吗?
I'm having an annoying issue with set_fact
,I set a var with value No
but once I call the var ansible converts it to False
is there a way around it?
推荐答案
我们可以使用多行标量YAML 语法来解决这个问题,并在文件内容中包含文本 No
.
We can use multi line scalar YAML syntax to get around this and have the text No
in the file contents.
考虑一个简单的文本文件 sample.txt
如下:
Consider a simple text file sample.txt
as below:
works? Yes
我正在使用 lineinfile
(Linux) 的示例,但对于 Windows 应该类似.一个包含以下任务的简单剧本:
I am using an example with lineinfile
(Linux), but should work similarly for Windows. A simple playbook with below tasks:
- set_fact:
var1: >
No
- lineinfile:
path: /tmp/sample.txt
line: "works? {{ var1 }}"
regexp: "^works"
当这个剧本运行时:
-works? Yes
+works? No
这篇关于Ansible set_fact 的 No 值转换为 False的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文