zoukankan      html  css  js  c++  java
  • Saltstack_使用指南07_远程执行-执行模块

    1. 主机规划

    远程执行教程文档

    https://docs.saltstack.com/en/latest/topics/tutorials/modules.html

    所有模块文档

    https://docs.saltstack.com/en/latest/ref/modules/all/index.html#all-salt-modules

    模块在机器上存在的位置

    1 [root@salt100 modules]# pwd
    2 /usr/lib/python2.7/site-packages/salt/modules
    3 [root@salt100 modules]# ll network.py
    4 -rw-r--r-- 1 root root 56636 Oct  8 23:56 network.py

    注意事项

    修改了master或者minion的配置文件,那么必须重启对应的服务。

    2. 使用格式

    1 # salt调用包括三个主要组成部分:
    2 salt '<target>' <function> [arguments]

    2.1. 指定目标

    上一篇文章详细说过,这里简单说下

     1 # target组件允许你过滤minion运行以下功能。默认的是minion ID,如下:
     2 salt '*' test.ping
     3 salt '*.example.org' test.ping
     4 
     5 # 也可以使用grains:
     6 salt -G 'os:Ubuntu' test.ping
     7 
     8 # 也可以使用正则表达式:
     9 salt -E 'virtmach[0-9]' test.ping
    10 
    11 # 也可以使用列表:
    12 salt -L 'foo,bar,baz,quo' test.ping
    13 
    14 # 或者多个目标类型可以使用复合指定:
    15 salt -C 'G@os:Ubuntu and webser* or E@database.*' test.ping

    2.2. 指定执行模块

    1 # function是由模块提供的一些功能。Salt中有大量可用functions。列出所有可用的functions如下:
    2 salt '*' sys.doc
    3 
    4 # 一些例子如下:
    5 # 显示当前所有可用的 minion
    6 salt '*' test.ping
    7 
    8 # 运行随意的shell命令:
    9 salt '*' cmd.run 'uname -a'  

    2.3. 执行参数

    1 # 使用空格作为分隔符
    2 salt '*' cmd.exec_code python 'import sys; print sys.version'  
    3 
    4 # 可选的,关键字参数也被支持:
    5 salt '*' pip.install salt timeout=5 upgrade=True
    6 # 改格式为: kwarg=argument

    3. 使用示例

    3.1. network

    https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.network.html#module-salt.modules.network

    3.2. service

    https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.rh_service.html#module-salt.modules.rh_service

    3.3. cp【可使用Salt-cp代替】

    https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.cp.html#module-salt.modules.cp

    另请参考:saltstack cp模块使用

    基本解释:

    1 salt根目录:在master中 file_roots 定义的路径 
    2 例如:假设在master中有如下定义: 
    3 file_roots:
    4   base:
    5     - /srv/salt
    6 
    7 那么:salt://vimrc指的实际路径是:/srv/salt/vimrc,这样做的好处是,可以满足state系统中环境的概念。

    示例:

     1 [root@salt100 other]# pwd
     2 /srv/salt/other
     3 [root@salt100 other]# ll /srv/salt/other/hosts 
     4 -rw-r--r-- 1 root root 276 Nov 25 17:59 /srv/salt/other/hosts
     5 [root@salt100 other]# salt -L 'salt01,salt02' test.ping
     6 salt01:
     7     True
     8 salt02:
     9     True
    10 [root@salt100 other]# salt -L 'salt01,salt02' cp.get_file salt://other/hosts /tmp/hehe  # 使用cp模块,拷贝到指定 minion 

    salt-cp使用

    salt-cp -L 'salt01,salt02' /etc/hosts /tmp/kkk  # 使用 salt-cp 拷贝【建议使用,方便一些】

    3.4. state

    https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.state.html#module-salt.modules.state    

  • 相关阅读:
    asp.net Post Get提交数据转Model实例
    ETL构建数据仓库五步法
    什么是数据仓库-数据仓库的基本概念
    简单的说下什么是数据仓库
    简单理解Socket
    Net中的反射使用入门
    JS---BOM
    jQuery Ajax 全解析
    Ajax与JSON的一些总结
    ASP.NET中验证控件的使用
  • 原文地址:https://www.cnblogs.com/zhanglianghhh/p/10674235.html
Copyright © 2011-2022 走看看