判断语句示例

判断添加用户

- 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

遗留问题,如何通知判断添加多个用户

posted @ 2023-01-22 10:56  mingtian是吧  阅读(10)  评论(0编辑  收藏  举报