zoukankan      html  css  js  c++  java
  • Saltstack常用模块

    Salt强大之处就是拥有众多模块,这些模块极大提高了我们的工作效率,而且还不断开发新的模块,这里就先列举一些常用模块的基本的应用。

    更多的模块和使用方法请参考官网:
    https://docs.saltstack.com/en/latest/ref/modules/all/

    cmd模块(实现远程的命令行调用执行类似于ansible的shell模块)

    # salt '*' cmd.run 'w'
    node23.com:
         19:07:18 up 12:27,  2 users,  load average: 0.00, 0.02, 0.00
        USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
        root     tty1     -                10:26    8:29m  0.08s  0.08s -bash
        root     pts/2    192.168.0.113    18:18    1.00s  0.45s  0.37s /usr/bin/python
    node24.com:
         02:51:02 up  8:40,  3 users,  load average: 0.00, 0.03, 0.00
        USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
        root     tty1     :0               18:12    8:40m  5.15s  5.15s /usr/bin/Xorg :
        root     pts/0    :0.0             18:13    8:28m  0.03s  0.03s /bin/bash
        root     pts/2    192.168.0.113    00:23    1:06m  0.08s  0.08s -bash
    

    cron模块(实现被控主机的crontab操作)

    添加计划任务

    #  salt 'node24.com' cron.set_job root '*' '*/2' '*' '*' '*' '/usr/bin/curl http://www.baidu.com >/dev/null 2>&1'                                         
    node24.com:
        new
    

    查看计划任务

    #  salt 'node24.com' cron.raw_cron root       
    node24.com:
        # Lines below here are managed by Salt, do not edit
        * */2 * * * /usr/bin/curl http://www.baidu.com >/dev/null 2>&1
    

    删除计划任务

    # salt 'node24.com' cron.rm_job root '/usr/bin/curl http://www.baidu.com >/dev/null 2>&1'  
    node24.com:
        removed
    

    file模块(文件操作模块)

    追加文件内容

    # salt 'node24.com' file.append /tmp/log.txt 
    > "test zhui jia wen jian nei rong" 
    > "jiu zhe yang ba"
    node24.com:
        Wrote 2 lines to "/tmp/log.txt"
    

    复制文件

    salt 'node24.com' file.copy /root/gitinstall.sh /tmp/gitinstall.sh
    node24.com:
        True
    

    找到tpm目录下大于0k且以sh结尾的文件

    # salt 'node24.com' file.find /tmp type=f name=*.sh size=+0k  
    node24.com:
        - /tmp/gitinstall.sh
    

    删除tpm目录下大于0k且以sh结尾的文件

    # salt 'node24.com' file.find /tmp type=f name=*.sh size=+0k delete
    node24.com:
        - /tmp/gitinstall.sh
    

    其他方法:
    file.mkdir 创建目录
    file.managed 保证文件存在且为对应状态
    file.recuse 保证目录存在且位对应状态
    file.absent 保证文件不存在,如果存在就删除

    pkg包管理模块

    安装软件

    # salt 'node24.com' pkg.install vim  
    node24.com:
        ----------
    

    其他方法:
    pkg.installed 安装软件,如果目标就开启没有就进行安装
    pkg.latest 安装最新版本如果不是最新的就进行升级
    pkg.remove 卸载
    pkg.purge 删除配置文件

    service 服务模块

    开机启动

    # salt 'node24.com' service.enable httpd     
    node24.com:
        True
    

    status模块(返回minion状态信息)

    返回内存信息

    salt 'node24.com' status.meminfo 
    
  • 相关阅读:
    形象理解ERP(转)
    禁用windows server 2008 域密码复杂性要求策略
    How to adding find,filter,remove filter on display method Form
    Windows Server 2008 R2激活工具
    How to using bat command running VS development SSRS report
    Creating Your First Mac AppGetting Started
    Creating Your First Mac AppAdding a Track Object 添加一个 Track 对象
    Creating Your First Mac AppImplementing Action Methods 实现动作方法
    Creating Your First Mac AppReviewing the Code 审查代码
    Creating Your First Mac AppConfiguring the window 设置窗口
  • 原文地址:https://www.cnblogs.com/iteemo/p/5548094.html
Copyright © 2011-2022 走看看