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

创建用户剧本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服务器查看创建删除成功

相关推荐
风清再凯4 天前
自动化工具ansible,以及playbook剧本
运维·自动化·ansible
IT乌鸦坐飞机4 天前
ansible部署数据库服务随机启动并创建用户和设置用户有完全权限
数据库·ansible·centos7
遇见火星17 天前
如何使用Ansible一键部署MinIO集群?
ansible
粥周粥17 天前
ANSIBLE
ansible
码农101号17 天前
Linux中ansible模块补充和playbook讲解
linux·运维·ansible
码农101号17 天前
Linux的Ansible软件基础使用讲解和ssh远程连接
ansible
烟雨书信18 天前
ANSIBLE运维自动化管理端部署
运维·自动化·ansible
碎碎-li18 天前
ANSIBLE(运维自动化)
运维·自动化·ansible
@donshu@21 天前
Linux运维-ansible-python开发-获取inventroy信息
linux·运维·ansible
Kendra91924 天前
Ansible
ansible