zoukankan      html  css  js  c++  java
  • Ansible常用模块之系统类模块

    cron模块

    管理远程主机上的计划任务

    [root@tiandong ansible]# ansible all -m cron -a "name='cron test' minute=5 hour=1 job='echo test'"

    每天15分执行

    [root@tiandong ansible]# ansible all -m cron -a "name='cron day test' minute=5 hour=1 day=*/3 job='echo test'"

    [root@tiandong ansible]# ansible all -m cron -a "name='test special time' special_time=reboot job='echo test'"

    定义计划任务,在重启时执行

    [root@tiandong ~]# ansible all -m cron -a "name='test special time' special_time=hourly job='echo test' backup=yes"

    存在相同的name,则会修改之前的计划任务,但是加了backup之后会先进行备份然后在创建计划任务

    [root@tiandong ~]# ansible all -m cron -a "name='test special time' state=absent backup=yes"

    删除计划任务。有backup参数就是先进行备份,backup_file备份的位置

    [root@tiandong ~]# ansible all -m cron -a "user=tom name='the special time' special_time=hourly job='echo test'"

    默认的计划任务是root用户,但是可以指定用户。

    在远程主机上查看

     

    [root@tiandong ~]# ansible all -m cron -a "user=tom name='the special time' special_time=hourly job='echo test' disabled=yes backup=yes"

    当要注释某个计划任务的时候,加disabled参数。

    Service模块

    管理远程主机上的服务

    [root@tiandong ~]# ansible all -m service -a "name=httpd state=started"

    启动远程主机上的httpd服务

    [root@tiandong ~]# ansible all -m service -a "name=httpd state=stopped"

    关闭远程主机上的httpd服务

    [root@tiandong ~]# ansible all -m service -a "name=httpd enabled=yes"

    远程主机上的httpd服务设置为开机自启动

    User模块

    管理远程主机上的用户,(创建用户,修改用户,删除用户为用户创建密钥对等)

    [root@tiandong ~]# ansible all -m user -a "name=thunder"

    创建用户thunder

    [root@tiandong ~]# ansible all -m user -a "name=thunder state=absent"

    删除用户thunder,但是不会删除家目录

    [root@tiandong ~]# ansible all -m user -a "name=thunder state=absent remove=yes"

    删除用户thunder,同时删除thunder的家目录信息

    [root@tiandong ~]# ansible all -m user -a "name=thunder comment='www.thunder.com'"

    注定用户的注释信息

     

    [root@tiandong ~]# ansible all -m user -a "name=winter group=thunder uid=600 shell=/sbin/nologin"

    添加一个用户,设置组,uid,以及shell

  • 相关阅读:
    HiveQL:数据定义
    linux学习整理
    Hive中问题解决整理
    Hive 数据类型和文件格式
    neo4j 简要安装步骤
    Leetcode 刷题笔记二 两数相加(使用链表) -- scala版本
    leetcode 刷题笔记一 两数之和 scala版本
    windows 安装 tensorflow
    elemnetui 下载,及引用
    cenos7 安装mysql
  • 原文地址:https://www.cnblogs.com/winter1519/p/9353042.html
Copyright © 2011-2022 走看看