Ansible实现剧本远程服务器创建、删除用户

时间:2024-09-30 12:13:11

创建用户剧本user_add.yaml

- hosts: 192.168.45.135
  remote_user: root
  tasks:
    - name: linux system add user list.
      user: name={{ item }} state=present
      with_items:
        - xiaoxin1
        - xiaoxin2
        - xiaoxin3
        - xiaoxin4

删除用户剧本user_delete.yaml

- hosts: 192.168.45.135
  remote_user: root
  tasks:
    - name: linux system add user list.
      user: name={{ item }} state=absent
      with_items:
        - xiaoxin1
        - xiaoxin2
        - xiaoxin3
        - xiaoxin4

执行脚本命令

ansible-playbook user_delete.yaml

执行结果

 登录135服务器查看创建删除成功