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

相关推荐
扑火的小飞蛾12 小时前
【Ansible学习笔记01】 批量执行 shell 命令
笔记·学习·ansible
oMcLin12 小时前
如何在 Red Hat Linux 服务器上使用 Ansible 自动化部署并管理多节点 Hadoop 集群?
linux·服务器·ansible
linux修理工3 天前
vagrant ubuntu 22.04 ansible 配置
ubuntu·ansible·vagrant
biubiubiu07064 天前
Ansible自动化
运维·自动化·ansible
秋4275 天前
ansible配置与模块介绍
ansible
秋4275 天前
ansible剧本
linux·服务器·ansible
码农101号6 天前
Ansible - Role介绍 和 使用playbook部署wordPress
android·ansible
2301_800050998 天前
Ansible
运维·ansible
阎*水10 天前
Ansible 核心要点总结
ansible
小安运维日记10 天前
RHCA - DO374 | Day09:自定义内容集和执行环境
linux·运维·服务器·系统架构·ansible·改行学it