判断语句 之 变量内容类型判断

参数 释义
string 判断字符串
upper 判断全大写
lower 判断全小写
- hosts: all
  tasks:
  - name: test string
    vars:
      msg: ABC
    debug:
      msg: "{{ msg }} is string"
    when: msg is string
    
  - name: test upper
    vars:
      msg: ABC
    debug:
      msg: "{{ msg }} is upper"
    when: msg is upper

  - name: test lower
    vars:
      msg: abc
    debug:
      msg: "{{ msg }} is lower"
    when: msg is lower
参数 释义
number 判断是数字
odd 判断是奇数
even 判断是偶数
- hosts: all
  tasks:
  - name: test number
    vars:
      msg: 123
    debug:
      msg: "{{ msg }} is number"
    when: msg is number

  - name: test odd
    vars:
      msg: 123
    debug:
      msg: "{{ msg }} is odd"
    when: msg is odd
    
  - name: test even
    vars:
      msg: 124
    debug:
      msg: "{{ msg }} is even"
    when: msg is even
参数 释义
subset() 判断列表子集
superset() 判断列表父集
- hosts: all
  vars:
    var1: [a,b,c]
    var2: [a]
  tasks:
  - name: test subset
    debug:
      msg: "{{var2}} in {{ var1 }}"
    when: var2 is subset(var1)
    
  - name: test superset
    debug:
      msg: "{{var1}} include {{ var2 }}"
    when: var1 is superset(var2)
posted @ 2023-01-24 13:33  mingtian是吧  阅读(15)  评论(0编辑  收藏  举报