ansible用户管理模块和剧本

ansible用户管理模块和剧本

group创建组模块

user创建⽤户模块

user模块

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

案例1:创建用户zhangsan

bash 复制代码
ansible web -m user -a 'name=zhangsan'
ansible web -a 'id zhangsan'

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

bash 复制代码
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格式

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

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

yaml 复制代码
[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'

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

bash 复制代码
---
- hosts: all
  tasks:
    - name: 添加定时任务
      cron:
        name: "同步时间"
        minute: "*/2"
        job: "/sbin/ntpdate ntp1.aliyun.com &>/dev/null"
        state: present
相关推荐
聊天QQ:688238869 小时前
光伏MPPT仿真:布谷鸟算法的奇妙结合
ansible
weixin_46681 天前
Ansible Playbook应用
网络·ansible
孪生质数-11 天前
Ansible基础入门
服务器·自动化·ansible·openstack
Empty_77711 天前
Ansible变量
服务器·github·ansible
哲Zheᗜe༘11 天前
学习Ansible Playbook 核心语法
网络·学习·ansible
凤凰战士芭比Q12 天前
Ansible剧本、变量、判断、循环
ansible
凤凰战士芭比Q12 天前
Ansible(安装、配置文件、命令行、常用模块)
linux·ansible
早睡冠军候选人16 天前
Ansible学习----管理复杂的 Play 和 Playbook 内容
运维·学习·云原生·ansible
雨奔16 天前
ansible使用教程
ansible
凡间客17 天前
Ansible安装与入门
linux·运维·ansible