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

相关推荐
Kendra91921 小时前
Ansible
ansible
꧁༺朝花夕逝༻꧂4 天前
Ansible小试牛刀
ansible
꧁༺朝花夕逝༻꧂4 天前
Ansible+Zabbix-agent2快速实现对多主机监控
运维·ansible
m0_628017594 天前
项目四.高可用集群_ansible
ansible
云攀登者-望正茂5 天前
通过 Ansible 在 Windows 2022 上安装 IIS Web 服务器
ansible
云攀登者-望正茂7 天前
使用 Ansible 在 Windows 服务器上安装 SSL 证书
ansible
tianyuanwo9 天前
Ansible自动化运维全解析:从设计哲学到实战演进
运维·自动化·ansible
哆啦A梦15889 天前
在golang中如何将已安装的依赖降级处理,比如:将 go-ansible/[email protected] 更换为 go-ansible/@v1.1.7
开发语言·golang·ansible
lifeng432110 天前
在 CentOS 上将 Ansible 项目推送到 GitHub 的完整指南
centos·github·ansible
运维成长记15 天前
ansible-playbook 进阶 接上一章内容
linux·服务器·ansible