ansible 变量检测是否定义

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/JackLiu16/article/details/82017386

如果需要的变量没有定义,那么可以skip或者使用jinja2的defined如下所示:

tasks:
    - shell: echo "I've got '{{ foo }}' and am not afraid to use it!"
      when: foo is defined
    - fail: msg="Bailing out. this play requires 'bar'"
      when: bar is undefined

---
- name: echo variable
  when:
    - api_interface is defined
    - neutron_external_interface is defined
    - storage_interface is undefined
  pause: seconds=10
 

参考:https://blog.csdn.net/kellyseeme/article/details/50609591

猜你喜欢

转载自blog.csdn.net/JackLiu16/article/details/82017386
今日推荐