Ansible-如何将布尔值传递给角色?
我正在努力调用一个取决于特定值的角色。目前我的剧本包括:Ansible-如何将布尔值传递给角色?,ansible,Ansible,我正在努力调用一个取决于特定值的角色。目前我的剧本包括: - name: "sandbox" hosts: "showroom:local" become: true become_user: "root" pre_tasks: - name: suicide test debug: var: branch_stop_suicide - debug: var: git_branch - debug:
- name: "sandbox"
hosts: "showroom:local"
become: true
become_user: "root"
pre_tasks:
- name: suicide test
debug:
var: branch_stop_suicide
- debug:
var: git_branch
- debug:
msg: git_branch not in branch_stop_suicide
roles:
- role: server-suicide
server_suicide_active: git_branch not in branch_stop_suicide
在调试中,我可以看到以下结果:
TASK [suicide test] **********************************************
ok: [52.59.218.32] => {
"branch_stop_suicide": [
"ADHOC-add-showroom-termination-role-test-17",
"integration",
"master"
]
}
TASK [debug] *******************************************************************
ok: [52.59.218.32] => {
"git_branch": "ADHOC-add-showroom-termination-role-test-17"
}
TASK [debug] *******************************************************************
ok: [52.59.218.32] => {
"msg": "git_branch not in branch_stop_suicide"
}
这已经显示了一个问题,因为如果一个变量位于另一个变量中,则将git\u branch not in branch\u stop\u sequestion视为字符串而不是test
因此,我的角色接收字符串而不是布尔值,并且无法执行正确的逻辑。如何在此处强制评估条件?您应该将您正在填写的支票包装起来,以便按照如下方式进行评估:
- debug:
msg: "{{ git_branch not in branch_stop_suicide }}"
这将产生您期望的布尔值
TASK [debug] *****************************************************************
ok: [localhost] => {
"msg": false
}
您应该包装您正在编写的支票,以便按照如下方式对其进行评估:
- debug:
msg: "{{ git_branch not in branch_stop_suicide }}"
这将产生您期望的布尔值
TASK [debug] *****************************************************************
ok: [localhost] => {
"msg": false
}