Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
变量使用的Ansible测试未定义另一个_Ansible - Fatal编程技术网

变量使用的Ansible测试未定义另一个

变量使用的Ansible测试未定义另一个,ansible,Ansible,我使用三元运算符返回定义的变量,否则返回另一个变量: {{ (variable1 is defined) | ternary(variable1, variable2) }} 这有点笨拙。有更好的方法吗?试试这个 - hosts: nodes gather_facts: false vars: var1: value1 tasks: - name: Show 1 debug: msg="{{ var1 | default('AAAAAA') }}"

我使用三元运算符返回定义的变量,否则返回另一个变量:

 {{ (variable1 is defined) | ternary(variable1, variable2) }}
这有点笨拙。有更好的方法吗?

试试这个

- hosts: nodes
  gather_facts: false

  vars:
    var1: value1

  tasks:

  - name: Show 1
    debug: msg="{{ var1 | default('AAAAAA') }}"

  - name: Show 2
    debug: msg="{{ var2 | default('BBBBBB') }}"