SaltStack常用的模块

SaltStack常用的模块


查看所有module列表

[root@node1 ~]# salt 'node1*' sys.list_modules
node1.example.com:
    - acl
    - aliases
    - alternatives
    - ansible
    - apache
    - archive
    - artifactory
    - beacons
    ...

查看指定module的所有function

[root@node1 ~]# salt 'node1*' sys.list_functions cmd
node1.example.com:
    - cmd.exec_code
    - cmd.exec_code_all
    - cmd.has_exec
    - cmd.powershell
    - cmd.powershell_all
    - cmd.retcode
    - cmd.run
    - cmd.run_all
    - cmd.run_bg
    - cmd.run_chroot
    - cmd.run_stderr
    ...

查看指定module的用法

[root@node1 ~]# salt 'node1*' sys.doc cmd
cmd.exec_code:

    Pass in two strings, the first naming the executable language, aka -
    python2, python3, ruby, perl, lua, etc. the second string containing
    the code you wish to execute. The stdout will be returned.

    All parameters from :mod:`cmd.run_all <salt.modules.cmdmod.run_all>` except python_shell can be used.
... 
SaltStack常用模块之network

network.active_tcp   返回所有活动的tcp连接

[root@node1 ~]# salt 'node1*' network.active_tcp
node1.example.com:
    ----------
    0:
        ----------
        local_addr:
            192.168.39.133
        local_port:
            4505
        remote_addr:
            192.168.39.134
        remote_port:
            55046

network.calc_net  通过IP和子网掩码计算出网段

[root@node1 ~]# salt '*' network.calc_net 192.168.39.202 255.255.255.0
node1.example.com:
    192.168.39.0/24

network.connect  测试minion至某一台服务器的网络是否连通

[root@node1 ~]# salt '*' network.connect baidu.com 80
node1.example.com:
    ----------
    comment:
        Successfully connected to baidu.com (39.156.69.79) on tcp port 80
    result:
        True
node2.example.com:
    ----------
    comment:
        Successfully connected to baidu.com (220.181.38.148) on tcp port 80
    result:
        True

network.default_route  查看默认路由

[root@node1 ~]# salt 'node1*' network.default_route
node1.example.com:
    |_
      ----------
      addr_family:
          inet
      destination:
          0.0.0.0
      flags:
          UG
      gateway:
          192.168.39.2
      interface:
          ens33
      netmask:
          0.0.0.0

network.get_fqdn  查看主机的fqdn(完全限定域名)

[root@node1 ~]# salt '*' network.get_fqdn
node2.example.com:
    node2.example.com
node1.example.com:
    node1.example.com

network.get_hostname  获取主机名

[root@node1 ~]# salt '*' network.get_hostname
node1.example.com:
    node1.example.com
node2.example.com:
    node2.example.com

network.get_route  查询到一个目标网络的路由信息

[root@node1 ~]# salt 'node1*' network.get_route 192.168.39.250
node1.example.com:
    ----------
    destination:
        192.168.39.250
    gateway:
        None
    interface:
        ens33
    source:
        192.168.39.133

network.in_subnet  判断当前主机是否在某一个网段内

[root@node1 ~]# salt '*' network.in_subnet 192.168.39.0/24
node1.example.com:
    True
node2.example.com:
    True

network.ping  使用ping命令测试到某主机的连通性

[root@node1 ~]# salt 'node1*' network.ping baidu.com
node1.example.com:
    PING baidu.com (39.156.69.79) 56(84) bytes of data.
    64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=128 time=54.7 ms
    64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=128 time=48.5 ms
    64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=3 ttl=128 time=50.6 ms
    64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=4 ttl=128 time=104 ms
    
    --- baidu.com ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3008ms
    rtt min/avg/max/mdev = 48.548/64.666/104.691/23.215 ms
SaltStack常用模块之service

service.available  判断指定的服务是否可用

[root@node1 ~]# salt '*' service.available httpd
node1.example.com:
    True
node2.example.com:
    True

service.get_all  获取所有正在运行的服务

[root@node1 ~]# salt 'node1*' service.get_all
node1.example.com:
    - NetworkManager
    - NetworkManager-dispatcher
    - NetworkManager-wait-online
    - arp-ethers
    - auditd
    - autovt@
    - basic.target
    - blk-availability
    - bluetooth.target
    ...

service.enabled  检查指定服务是否开机自动启动

[root@node1 ~]# salt '*' service.enabled httpd
node2.example.com:
    False
node1.example.com:
    False

service.enable  设置指定服务开机自动启动

[root@node1 ~]# salt '*' service.enable httpd
node1.example.com:
    True
node2.example.com:
    True

service.reload  重新加载指定服务

[root@node1 ~]# salt '*' service.reload httpd
node1.example.com:
    True
node2.example.com:
    True
SaltStack常用模块之pkg

pkg.install  安装软件

[root@node1 ~]# salt '*' pkg.install unzip
node1.example.com:
    ----------
    unzip:
        ----------
        new:
            6.0-20.el7
        old:

pkg.owner  列出指定文件是由哪个包提供的

[root@node1 ~]# salt '*' pkg.owner /bin/wget
node1.example.com:
    wget
node2.example.com:
    wget

pkg.remove  卸载指定软件

[root@node1 ~]# salt '*' pkg.remove unzip
node2.example.com:
    ----------
    unzip:
        ----------
        new:
        old:
            6.0-20.el7
node1.example.com:
    ----------
    unzip:
        ----------
        new:
        old:
            6.0-20.el7
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值