• saltstack之(四)远程执行及常用模块


    前几篇文章已经完成了saltstack的安装、认证,从这篇文章开始学习使用saltstack的远程执行。

    1.salt远程执行命令详解
    Usage: salt [options] '<target>' <function> [arguments]

    [options] :此选项指定以何种方式匹配target。
     : 通配符匹配
     -N: 匹配分组nodegroup
     -E: 正则匹配
     -G:grains匹配
     -I: pillar匹配
     -L: 列表匹配,使用逗号或者空格匹配。
     -S: 使用IP地址匹配

    '<target>':匹配minion客户端

    ①.与minion id有关
    id:
     salt '192.168.3.1' test.ping
    通配符:
     salt '*1' test.ping
     salt 'node?.xkops.com' test.ping
     salt 'node[1-2].xkops.com' test.ping
     salt 'node[!1].xkops.com' test.ping

    *注释:为了实验,此处可以更改minion id为node1.xkops.com和node2.xkops.com,根据自己需要修改。

    正则匹配:
     salt -E '(node1|node2).xkops.com' test.ping

    ②.与minion id无关
     salt -G 'os:CentOs' test.ping
     salt -S '192.168.3.0/24' test.ping


    <function>:
    查看系统支持的模块
    [root@node1 ~]# salt '192.168.3.1' sys.list_modules
    查看某一模块所支持的方法
    [root@node1 ~]# salt '192.168.3.1' sys.list_functions test
    查看某一模块的用法
    [root@node1 ~]# salt '192.168.3.1' sys.doc test

    2.常用的模块及方法
    test模块(test.ping)
    用法:
    salt '*' test.ping

    cmd模块(cmd.run)
    用法:
    salt '*' cmd.run "ls -l | awk '/foo/{print $2}'"

    file模块(file.copy)
    用法:
    salt '*' file.copy /path/to/src /path/to/dst --文件
    salt '*' file.copy /path/to/src_dir /path/to/dst_dir recurse=True --目录
    salt '*' file.copy /path/to/src_dir /path/to/dst_dir recurse=True remove_existing=True --目录,若存在则覆盖


    cp模块(cp.get_file)
    用法:
    salt '*' cp.get_file salt://path/to/file /minion/dest

    salt '*' cp.get_dir salt://path/to/dir /minion/dest


    user模块(user.add)
    用法:
    salt '*' user.add name <uid> <gid> <groups> <home> <shell>

  • 相关阅读:
    linux自动清理30天之前的文件
    Oracle树查询及相关函数
    jackson循环引用导致序列化stackOverFlow的解决
    java核心技术36讲笔记
    Quartz学习
    Quartz学习
    java核心技术36讲
    git常用命令
    CTCall简介(后续会继续补充)
    自定义导航栏,隐藏导航栏底部的灰色线条
  • 原文地址:https://www.cnblogs.com/xkops/p/5482486.html
Copyright © 2020-2023  润新知