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

  • 相关阅读:
    个人报告04
    个人报告03
    构建之法阅读笔记07
    个人报告02
    第二次冲刺个人报告01
    第二阶段个人总结5
    第十三周学习进度情况
    第二阶段个人总结4(5.28)
    第二阶段个人总结3(5.27)
    课堂作业之找小水王
  • 原文地址:https://www.cnblogs.com/winter1519/p/9353042.html
Copyright © 2011-2022 走看看