判断语句 之 变量判断

参数 释义 示例
defined 变量已定义 when: username is defined
undefind 变量未定义 when: username is undfined
none 变量已定义未赋值 when: username is none
- hosts: all
  tasks:
  - name: test defined
    vars:
      username: test1
    debug:
      msg: "{{ username }} is defined"
    when: username is defined
  - name: test undefined
    vars:
    debug:
      msg: "username is undefined"
    when: username is undefined
  - name: test none
    vars:
      username:
    debug:
      msg: "{{username}} is none"
    when: username is none
posted @ 2023-01-24 12:24  mingtian是吧  阅读(13)  评论(0编辑  收藏  举报