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

相关推荐
爱网络爱Linux3 天前
RHCSA+RHCE 10.0全新升级!红帽Ansible自动化运维
运维·自动化·ansible·rhce认证·rhel1o·linux10·rhce10
码上上班8 天前
Ansible课程
ansible
至乐活着11 天前
Ansible自动化运维实战:从零部署高可用Nginx+静态网站集群
ansible·自动化运维·devops·playbook·配置管理
John Song14 天前
ansible-playbook常用的检查命令
windows·ansible
明航咨询_贾老师16 天前
RHCA Ansible高级自动化(DO374)认证信息整理
运维·自动化·ansible·rhca·红帽认证
有毒的教程20 天前
Ansible批量操作自动化完整教程:批量部署服务、配置同步、软件更新实战
运维·自动化·ansible
Hy行者勇哥25 天前
用Cursor智能编写Ansible/Terraform脚本,打通CI/CD链路
ci/cd·ansible·terraform
芷栀夏1 个月前
飞牛NAS怎么部署Immich?家庭照片自动备份与远程访问教程
服务器·nginx·ansible
悠然南风1 个月前
Ansible常见模块总结及LDAP Role 编写与调试
ansible
祺风挽楠2 个月前
ansible编辑
网络·ansible