常常用于判断前一个命令执行的结果.
参数 | 释义 | 示例 |
---|---|---|
success | 执行状态为成功为真 | when: result is success |
succeeded | ||
failure | 执行状态为失败为真 | when: result is failure |
failed | ||
change | 执行状态为change为真 | when: result is chang |
changed | ||
skip | 执行状态为skip为真 | when result is skip |
skipped |
- hosts: all
vars:
- username: test1
tasks:
- name: detect whether the user exists
shell:
id {{ username }}
register: result
ignore_errors: true
- name: debug
debug:
msg: "{{ username }} exsist,nothing to do"
when: result is success
- name: user add {{ username }}
user:
name: "{{ username }}"
state: present
when: result is failure
标签:语句,username,判断,name,skip,when,result,执行
From: https://www.cnblogs.com/wangend/p/17066005.html