ansible用户管理模块和剧本

ansible用户管理模块和剧本

group创建组模块

user创建⽤户模块

user模块

user模块
name⽤户名
uid指定uid
group指定⽤户组
shell指定命令解释器
create_home是否创建家⽬录(yes/no)
statepresent 添加
absent删除

案例1:创建用户zhangsan

ansible web -m user -a 'name=zhangsan'
ansible web -a 'id zhangsan'

案例2:创建用户lisi,指定uid为10010,命令解释器为/sbin/nologin,不创建家目录

ansible web -m user -a 'name=lisi uid=10010 shell=/sbin/nologin create_home=no state=present'
ansible web -a 'grep lisi /etc/passwd'

剧本

剧本的格式如下:yaml格式

---
- hosts: all  ---------》 被管理的主机
  vars:    ----> 变量
   filename: test.txt
  tasks:           --------》具体要执行的任务
   - name: touch file    -----> 任务描述
     shell: touch /tmp/{{ filename }} -----》对应模块

案例1:在所有机器的 /opt 目录下创建 application.log文件

[root@m01 scripts]# cat 01-hello.yaml 
---
- hosts: all
  tasks:
    - name: 在/opt目录下创建application.log文件
      shell: touch /opt/application.log
      
ansible all -a 'ls -l /opt'

案例二:添加定时同步时间的定时任务

---
- hosts: all
  tasks:
    - name: 添加定时任务
      cron:
        name: "同步时间"
        minute: "*/2"
        job: "/sbin/ntpdate ntp1.aliyun.com &>/dev/null"
        state: present
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

让美好继续发生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值