要从Ansible事实值中删除引号,可以使用Ansible的过滤器来处理。下面是一个包含代码示例的解决方法:
- name: 删除引号
hosts: localhost
gather_facts: False
tasks:
- name: 设置带引号的变量
set_fact:
my_var: "'example'"
- name: 删除引号
set_fact:
my_var_without_quotes: "{{ my_var | regex_replace('^\'|\'$', '') }}"
- name: 打印结果
debug:
var: my_var_without_quotes
在上面的示例中,我们首先设置一个带有引号的变量my_var
。然后使用regex_replace
过滤器将引号从变量中删除,并将结果存储在my_var_without_quotes
变量中。最后,使用debug
模块打印删除引号后的变量。
运行上面的代码示例将输出以下结果:
TASK [打印结果] **************************************************************************************************************************
ok: [localhost] => {
"my_var_without_quotes": "example"
}
在这个例子中,引号已成功从变量中移除。