我遇到了一个问题,希望能得到你的帮助,谢谢!
示例:
- hosts: localhost
tasks:
- name: "set variable"
set_fact:
test1:
a: 1
- name: "assignment"
set_fact:
test2:
a: "{{test1.a}}"
- name: "print test2"
debug:
var: test2产出如下:
"test2":{ "a": "1"}我期望的是:
"test2":{ "a": 1}发布于 2021-02-08 14:17:32
这是默认行为。我不知道你为什么会期望在没有引号的情况下显示这个值。
也许您正在考虑将值转换为字符串,但事实并非如此。
- name: set variable
set_fact:
test1:
a: 1
- name: check if variable is integer
assert:
that:
- test1.a | type_debug == "int"
- test1.a is regex("^[0-9]+$")
- name: assignment
debug:
var: "{{ test1.a }}"https://stackoverflow.com/questions/66102524
复制相似问题