判断语句示例
判断添加用户
- 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.rc == 0
- name: user add {{ username }}
user:
name: "{{ username }}"
state: present
when: result.rc != 0
遗留问题,如何通知判断添加多个用户