• 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

  • 相关阅读:
    【PHP】 lumen 输出sql信息
    Go学习笔记-使用MySQL数据库
    PHP检测函数是否存在
    Javascript边框闪烁提示
    【转】Ubuntu 16.04下 Mysql 5.7.17源码编译与安装
    python-mysql windows diver地址
    【转载】Python Flask 开发环境搭建(Windows)
    【转载】agentzh 的 Nginx 教程(版本 2016.07.21)
    【转载】写给新手看的Flask+uwsgi+Nginx+Ubuntu部署教程
    【转载】从零开始搭建论坛(三):Flask框架简单介绍
  • 原文地址:https://www.cnblogs.com/winter1519/p/9353042.html
Copyright © 2020-2023  润新知