当前位置: 首页 > article >正文

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

http://www.kler.cn/news/333301.html

相关文章:

  • 【Linux】深入理解 Linux 系统命令:网络配置、压缩打包与其他常用命令
  • 芝法酱学习笔记(0.6)——nexus与maven私库
  • ReactJSX使用
  • 【环境配置】科研小白Windows下安装Git
  • 【LeetCode】每日一题 2024_10_5 完成旅途的最少时间(二分答案)
  • 大厂面试真题-介绍以下Docker的Overlay网络
  • 【漏洞复现】泛微OA E-Office do_excel.php 任意文件写入漏洞
  • 模拟算法(1)_替换所有的问号
  • C# 无边框窗体,加阴影效果、多组件拖动、改变大小等功能完美实现优化版效果体验
  • 【Linux】进程优先级、调度、命令行参数:从理论到实践(二)
  • 进程状态及优先级
  • 快速扩展随机数算法
  • Python入门--函数
  • Python批量下载PPT模块并实现自动解压
  • Vue中使用ECharts实现热力图的详细教程
  • 【SpringBoot详细教程】-10-SpringBoot整合swagger【持续更新】
  • 10/1 力扣 49.字母异位词分组
  • 安装Rust
  • 解决json格式转换被特殊字符截断问题
  • Vuex使用指南:案例、用法和知识点总结