zoukankan      html  css  js  c++  java
  • 深入学习saltstack远程执行(四)

    结构:

    命令:salt(固定的)

    目标:‘*’    

    模块:cmd.run   一共有150多种模块

    返回:执行后返回的结构

    详解目标

                        1 minion ID(ID名字)

                        2 通配符  (*,daxian00[1|2|3],daxian00[1-3]等)

                        3  列表     (salt -L 'daxian001,daxian002' test.ping)

                        4 正则表达式(slat -E 'daxian(001|002)*' test.ping)

                        所有匹配目标的方式,都可以用到TOPfile里面指定

      

    详解模块(常用的)

    显示arp表  

     salt '*' network.arp   

    显示主机名          

    salt '*' network.get_hostname
    web01:
    web02
    web02:
    web03

    查看服务是否存活

    salt '*' service.available sshd
    web01:
    True
    web02:
    True

     查看所有正在运行的服务

    salt '*' service.get_all

    重载

    salt '*' service.reload <service name>

    重启

    salt '*' service.restart <service name>

    启动

    salt '*' service.start <service name>

    状态

    salt '*' service.status <service name>

    停止

    salt '*' service.stop <service name>

    拷贝文件

    salt-cp '*' /etc/hosts /tmp/

    查看top都干什么事情

    salt '*' state.show_top

    返回程序:

       将返回的程序返回到mysql 数据库里

       

    编写状态模块:

      放在:/srv/salt/_modules

      命名: 文件名就是模块名 my_disk.py

      

    def list():
      cmd = 'df -h'
      ret = __salt__['cmd.run'](cmd)
    return ret

    刷新

    salt '*' saltutil.sync_modules

    会把文件刷新到minion端

     /var/cache/salt/minion/extmods/

    执行

    salt '*' my_disk.list

                     

  • 相关阅读:
    1、如何使用Azure Rest API创建虚拟机
    Ansible---2的Roles使用
    linux下的shell脚本
    生成器 yield和协程
    xshell
    markdown的使用
    加密
    Hbuilder打包app
    尾递归
    jupyter
  • 原文地址:https://www.cnblogs.com/sky00747/p/8258744.html
Copyright © 2011-2022 走看看