[英]How to use when condition in Ansible?
I cannot figure out this Ansible task 我无法弄清楚这个艰巨的任务
i run my playbook ansible-playbook play.yml -e proxyHost=$proxyHost -e proxyPort=$proxyPort
我运行我
ansible-playbook play.yml -e proxyHost=$proxyHost -e proxyPort=$proxyPort
- name: Set proxy when provided
set_fact: proxyproperty=" -Dhttp.proxyHost={{ proxyHost }} -Dhttp.proxyPort={{ proxyPort }} -Dhttps.proxyHost={{ proxyHost }} -Dhttps.proxyPort={{ proxyPort }} -Dhttp.nonProxyHosts=localhost|127.0.0.1|{{ ip }}|{{ fqdn }}|{{ hostName }}"
when: proxyHost is defined
So why is it when i have not set $ProxyHost
this ansible task is still being triggered? 那么,为什么在我未设置
$ProxyHost
仍会触发该任务呢? What am i missing? 我想念什么?
Python (hence Ansible) differentiates between an undefined variable and a variable with an empty value. Python(因此为Ansible)区分未定义的变量和具有空值的变量。
You define the proxyHost
variable in Ansible, but in case when $proxyHost
is undefined in shell/environment, you assign proxyHost
an empty value. 您定义
proxyHost
在Ansible变量,但在当案$proxyHost
壳/环境是不确定的,你指定proxyHost
空值。
You need, for example, to compare it to an empty string: 例如,您需要将其与空字符串进行比较:
when: proxyHost != ''
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.