zoukankan      html  css  js  c++  java
  • Ansible命令模块(group模块 user模块 cron模块 )

    1.group模块

    1)帮助语法

    EXAMPLES:
    - name: Ensure group "somegroup" exists
      group:
        name: somegroup                #组名字
        state: 
            present                    #创建用户组
            absent                    #删除用户组
        gid: 666                    #用户组ID

    2)实例

    #创建用户组
    [root@m01 ~]# ansible web_group -m group -a 'name=www state=present gid=666'
    
    #删除用户组
    [root@m01 ~]# ansible web_group -m group -a 'name=www state=absent'

    2.user模块

    1)帮助语法

    - name: Add the user 'johnd' with a specific uid and a primary group of 'admin'
      user:
        name: johnd                            #用户名
        comment: John Doe                    #用户的注释
        uid: 1040                            #用户id
        group: admin                        #用户的组
        groups: admins,developers             #指定附加组
        shell: /bin/bash                    #指定登录脚本
        append: yes                            #添加附加组时使用
        remove: yes                            #移除家目录
        generate_ssh_key: yes                 #是否生成密钥对
        ssh_key_bits: 2048                    #秘钥加密的位数
        ssh_key_file: .ssh/id_rsa             #秘钥文件
        expires: 1422403387                     #用户的有效时间
        state:
            present                            #添加用户
            absent                            #删除用户
        create_home:yes/no                     #是否创建家目录
        password                            #给用户添加密码(单引号)

    2)实践

    #1.创建用户
    [root@m01 ~]# ansible web_group -m user -a 'name=www uid=666 group=www shell=/sbin/nologin state=present'
    
    #2.仅删除用户
    [root@m01 ~]# ansible web_group -m user -a 'name=www state=absent'
    
    #3.删除用户及用户组
    [root@m01 ~]# ansible web_group -m user -a 'name=www state=absent remove=yes'
    
    #注意:
        1.如果用户名字跟组名字相同,删除用户是会将组也删除
        2.当组下面有多个用户,删除的与组同名的用户也不会删除组

    3.cron模块

    1)帮助语法

    EXAMPLES:
    - name: Ensure a job that runs at 2 and 5 exists. Creates an entry like "0 5,2 * * ls -alh > /d
      cron:
        name: "check dirs"                    #定时任务的注释
        minute: "0"                            #分钟
        hour: "5,2"                            #小时
        day: "2"                            #日
        month: "2"                            #月
        weekday: "2"                        #周
        job: "ls -alh > /dev/null"              #定时任务的内容
        state: 
            absent                            #删除定时任务
            present                            #添加定时任务

    2)实践

    #1.添加定时任务
    [root@m01 ~]# ansible web01 -m cron -a 'name="时间同步" minute=*/10 job="/usr/sbin/ntpdate time1.aliyun.com &> /dev/null"'
    
    #2.修改定时任务(不修改名字,只修改内容)
    [root@m01 ~]# ansible web01 -m cron -a 'name="时间同步" job="/usr/sbin/ntpdate time1.aliyun.com &> /dev/null"'
    
    #3.删除定时任务(一定要用name参数)
    [root@m01 ~]# ansible web01 -m cron -a 'name="时间同步" state=absent'
    
    #4.注释定时任务
    [root@m01 ~]# ansible web01 -m cron -a 'name="时间同步" job="/usr/sbin/ntpdate time1.aliyun.com &> /dev/null" disabled=yes'
  • 相关阅读:
    [译文] 实体与值对象到底是不是一回事?
    实现 WebApi 自托管服务宿主于 WinForms 及其交互
    [译文] C# 8 已成旧闻, 向前, 抵达 C# 9!
    [译文] 为什么你在 C# 里总是应该使用 "var" 关键字
    通过设置iis在局域网中访问网页
    windows 10 安装使用kafka
    ASP.NET Core 2.1 中的 HttpClientFactory (Part 4) 整合Polly实现瞬时故障处理
    ASP.NET Core 2.1 中的 HttpClientFactory (Part 3) 使用Handler实现传出请求中间件
    ASP.NET Core 2.1 中的 HttpClientFactory (Part 2) 定义命名化和类型化的客户端
    Asp.net Core 2.0 OpenId Connect Handler缺失Claims?
  • 原文地址:https://www.cnblogs.com/chenlifan/p/13777248.html
Copyright © 2011-2022 走看看