Ansible:变量未定义时如何通过条件

问题描述

我试图将以下字典合为一个,但在未定义变量之一的情况下努力通过条件。

  - set_fact:
      final_list: "{{ final_list|default({}) | combine( {item.key:item.value} ) }}"
    with_dict:
      - "{{ containeruplist }}"
      - "{{ containerexitedlist }}"
    when: (containeruplist is defined) or (containerexitedlist is defined)

这是我的代码

ok: [vm1.nodekite.com] => {
"final_list": {
   "service": "service-test-app","platform-service": "service-dev-app"
    "Nginx": "www-service"
}
}

这是输出

containeruplist is populated or containerexitedlist is undefined
containeruplist is undefined or containerexitedlist is populated
containeruplist is populated or containerexitedlist is populated

但是在未定义变量之一的情况下如何传递所有3个条件。

when: (containeruplist is defined) or (containerexitedlist is defined)

我尝试使用navigator.geolocation.getCurrentPosition(function(position) { locations.push(/* ... */); }) console.log(locations); 仍然抛出{“ msg”:“'containerexitedlist'未定义”“}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)