SaltStack常用模块

1. SaltStack模块介绍

Module是日常使用SaltStack接触最多的一个组件,其用于管理对象操作,这也是SaltStack通过Push的方式进行管理的入口,比如我们日常简单的执行命令、查看包安装情况、查看服务运行情况等工作都是通过SaltStack Module来实现的。

当安装好Master和Minion包后,系统上会安装很多Module,大家可以通过以下命令查看支持的所有Module列表:

//查看所有module列表
[root@localhost ~]# salt '192.168.11.132' sys.list_modules
192.168.11.132:
    - acl
    - aliases
    - alternatives
    - ansible
    - archive
    - artifactory
    - baredoc
    - beacons
    - bigip
    - btrfs
    - buildout
    - chroot
    - cloud
    - cmd
    - composer
    - config
    - consul
.......
//查看指定module的所有function
[root@localhost ~]# salt '192.168.11.132' sys.list_functions cmd
192.168.11.132:
    - 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
    - cmd.run_stdout
    - cmd.script
    - cmd.script_retcode
    - cmd.shell
    - cmd.shell_info
    - cmd.shells
    - cmd.tty
    - cmd.which
    - cmd.which_bin

2. SaltStack常用模块

2.1 SaltStack常用模块之network

2.1.1 network.active_tcp


[root@localhost ~]# salt '*' network.active_tcp
返回所有活动的tcp连接
192.168.11.120:
    ----------
    0:
        ----------
        local_addr:
            192.168.11.120
        local_port:
            22
        remote_addr:
            192.168.11.135
        remote_port:
            57541
    1:
        ----------
        local_addr:
            192.168.11.120
        local_port:
            4505
        remote_addr:
            192.168.11.120
        remote_port:
            48894
    2:
        ----------
        local_addr:
            192.168.11.120
        local_port:
            4505
        remote_addr:
            192.168.11.132
        remote_port:
            39502
    3:
        ----------
        local_addr:
            192.168.11.120
        local_port:
            22
        remote_addr:
            192.168.11.135
        remote_port:
            57052
    4:
        ----------
        local_addr:
            192.168.11.120
        local_port:
            48894
        remote_addr:
            192.168.11.120
        remote_port:
            4505
    5:
        ----------
        local_addr:
            192.168.11.120
        local_port:
            22
        remote_addr:
            192.168.11.135
        remote_port:
            57540
    6:
        ----------
        local_addr:
            192.168.11.120
        local_port:
            4506
        remote_addr:
            192.168.11.132
        remote_port:
            33152
192.168.11.132:
    ----------
    0:
        ----------
        local_addr:
            192.168.11.132
        local_port:
            22
        remote_addr:
            192.168.11.135
        remote_port:
            57079
    1:
        ----------
        local_addr:
            192.168.11.132
        local_port:
            39502
        remote_addr:
            192.168.11.120
        remote_port:
            4505
    2:
        ----------
        local_addr:
            192.168.11.132
        local_port:
            22
        remote_addr:
            192.168.11.135
        remote_port:
            57078

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

[root@localhost ~]# salt '*' network.calc_net 192.168.11.132 255.255.255.0
192.168.11.120:
    192.168.11.0/24
192.168.11.132:
    192.168.11.0/24

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

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

2.1.4 network.default_route
查看默认路由

[root@localhost ~]# salt '*' network.default_route
192.168.11.132:
    |_
      ----------
      addr_family:
          inet
      destination:
          0.0.0.0
      flags:
          UG
      gateway:
          192.168.11.2
      interface:
          ens160
      netmask:
          0.0.0.0
192.168.11.120:
    |_
      ----------
      addr_family:
          inet
      destination:
          0.0.0.0
      flags:
          UG
      gateway:
          192.168.11.2
      interface:
          ens160
      netmask:
          0.0.0.0

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

[root@master ~]#  salt '*' network.get_fqdn
192.168.11.120:
    master
192.168.11.132:
    minion

2.1.6 network.get_hostname
获取主机名

[root@master ~]#  salt '*' network.get_hostname
192.168.11.120:
    master
192.168.11.132:
    minion

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

[root@master ~]#  salt '*' network.get_route 192.168.11.132
192.168.11.120:
    ----------
    destination:
        192.168.11.132
    gateway:
        None
    interface:
        ens160
    source:
        192.168.11.120
192.168.11.132:
    ----------
    destination:
        192.168.11.132
    gateway:
        None
    interface:
        lo
    source:
        192.168.11.132

2.1.8 network.hw_addr
返回指定网卡的MAC地址

[root@master ~]# salt '*' network.hw_addr ens160
192.168.11.120:
    00:0c:29:44:99:f6
192.168.11.132:
    00:0c:29:33:62:a0

2.1.9 network.ifacestartswith
从特定CIDR检索接口名称

[root@master ~]#  salt '*' network.ifacestartswith 192.168
192.168.11.120:
    - ens160
192.168.11.132:
    - ens160

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

[root@master ~]#  salt '*' network.in_subnet 192.168.11.0/24
192.168.11.120:
    True
192.168.11.132:
    True

2.1.11 network.interface
返回指定网卡的信息

[root@master ~]# salt '*' network.interface ens160
192.168.11.120:
    |_
      ----------
      address:
          192.168.11.120
      broadcast:
          192.168.11.255
      label:
          ens160
      netmask:
          255.255.255.0
192.168.11.132:
    |_
      ----------
      address:
          192.168.11.132
      broadcast:
          192.168.11.255
      label:
          ens160
      netmask:
          255.255.255.0

2.1.12 network.interface_ip
返回指定网卡的IP地址

[root@master ~]#  salt '*' network.interface_ip ens160
192.168.11.120:
    192.168.11.120
192.168.11.132:
    192.168.11.132

2.1.13 network.interfaces
返回当前系统中所有的网卡信息

[root@master ~]# salt '*' network.interfaces
192.168.11.120:
    ----------
    ens160:
        ----------
        hwaddr:
            00:0c:29:44:99:f6
        inet:
            |_
              ----------
              address:
                  192.168.11.120
              broadcast:
                  192.168.11.255
              label:
                  ens160
              netmask:
                  255.255.255.0
        inet6:
            |_
              ----------
              address:
                  fe80::6258:d45c:6eb2:b334
              prefixlen:
                  64
              scope:
                  link
        up:
            True
    lo:
        ----------
        hwaddr:
            00:00:00:00:00:00
        inet:
            |_
              ----------
              address:
                  127.0.0.1
              broadcast:
                  None
              label:
                  lo
              netmask:
                  255.0.0.0
        inet6:
            |_
              ----------
              address:
                  ::1
              prefixlen:
                  128
              scope:
                  host
        up:
            True
192.168.11.132:
    ----------
    ens160:
        ----------
        hwaddr:
            00:0c:29:33:62:a0
        inet:
            |_
              ----------
              address:
                  192.168.11.132
              broadcast:
                  192.168.11.255
              label:
                  ens160
              netmask:
                  255.255.255.0
        inet6:
            |_
              ----------
              address:
                  fe80::4d29:c7bd:64e9:f7bc
              prefixlen:
                  64
              scope:
                  link
        up:
            True
    lo:
        ----------
        hwaddr:
            00:00:00:00:00:00
        inet:
            |_
              ----------
              address:
                  127.0.0.1
              broadcast:
                  None
              label:
                  lo
              netmask:
                  255.0.0.0
        inet6:
            |_
              ----------
              address:
                  ::1
              prefixlen:
                  128
              scope:
                  host
        up:
            True

2.1.14 network.ip_addrs
返回一个IPv4的地址列表
该函数将会忽略掉127.0.0.1的地址

192.168.11.120:
    - 192.168.11.120
192.168.11.132:
    - 192.168.11.132

2.1.15 network.netstat
返回所有打开的端口和状态

[root@master ~]# salt '*' network.netstat
192.168.11.120:
    |_
      ----------
      inode:
          701
      local-address:
          127.0.0.1:323
      program:
          chronyd
      proto:
          udp
      recv-q:
          0
      remote-address:
          0.0.0.0:*
      send-q:
          0
      user:
          0
    |_
      ----------
      inode:
          702
      local-address:
          [::1]:323
      program:
          chronyd
      proto:
          udp
      recv-q:
          0
      remote-address:
          [::]:*
      send-q:
          0
      user:
          0
    |_
      ----------
      inode:
          983
      local-address:
          0.0.0.0:22
      program:
          sshd
      proto:
          tcp
      recv-q:
          0
      remote-address:
          0.0.0.0:*
      send-q:
          128
      state:
          LISTEN
      user:
          0
    |_
      ----------
      inode:
          76236
      local-address:
          0.0.0.0:4505
      program:
          salt-master
      proto:
          tcp
      recv-q:
          0
      remote-address:
          0.0.0.0:*
      send-q:
          128
      state:
          LISTEN
      user:
          0
    |_
      ----------
      inode:
          76240
      local-address:
          0.0.0.0:4506
      program:
          salt-master
      proto:
          tcp
      recv-q:
          0
      remote-address:
          0.0.0.0:*
      send-q:
          128
      state:
          LISTEN
      user:
          0
    |_
      ----------
      inode:
          111690
      local-address:
          192.168.11.120:22
      program:
          sshd
      proto:
          tcp
      recv-q:
          0
      remote-address:
          192.168.11.135:57541
      send-q:
          0
      state:
          ESTABLISHED
      user:
          0
    |_
      ----------
      inode:
          133245
      local-address:
          192.168.11.120:4505
      program:
          salt-master
      proto:
          tcp
      recv-q:
          0
      remote-address:
          192.168.11.120:48894
      send-q:
          0
      state:
          ESTABLISHED
      user:
          0
    |_
      ----------
      inode:
          0
      local-address:
          192.168.11.120:35088
      program:
      proto:
          tcp
      recv-q:
          0
      remote-address:
          192.168.11.120:4506
      send-q:
          0
      state:
          TIME-WAIT
      user:
          0
    |_
      ----------
      inode:
          133743
      local-address:
          192.168.11.120:4505
      program:
          salt-master
      proto:
          tcp
      recv-q:
          0
      remote-address:
          192.168.11.132:39502
      send-q:
          0
      state:
          ESTABLISHED
      user:
          0
    |_
      ----------
      inode:
          0
      local-address:
          127.0.0.1:33736
      program:
      proto:
          tcp
      recv-q:
          0
      remote-address:
          127.0.0.1:4506
      send-q:
          0
      state:
          TIME-WAIT
      user:
          0
    |_
      ----------
      inode:
          33774
      local-address:
          192.168.11.120:22
      program:
          sshd
      proto:
          tcp
      recv-q:
          0
      remote-address:
          192.168.11.135:57052
      send-q:
          0
      state:
          ESTABLISHED
      user:
          0
    |_
      ----------
      inode:
          130964
      local-address:
          192.168.11.120:48894
      program:
          salt-minion
      proto:
          tcp
      recv-q:
          0
      remote-address:
          192.168.11.120:4505
      send-q:
          0
      state:
          ESTABLISHED
      user:
          0
    |_
      ----------
      inode:
          110854
      local-address:
          192.168.11.120:22
      program:
          sshd
      proto:
          tcp
      recv-q:
          0
      remote-address:
          192.168.11.135:57540
      send-q:
          0
      state:
          ESTABLISHED
      user:
          0
    |_
      ----------
      inode:
          105733
      local-address:
          192.168.11.120:4506
      program:
          salt-master
      proto:
          tcp
      recv-q:
          0
      remote-address:
          192.168.11.132:33152
      send-q:
          0
      state:
          ESTABLISHED
      user:
          0
    |_
      ----------
      inode:
          0
      local-address:
          127.0.0.1:33732
      program:
      proto:
          tcp
      recv-q:
          0
      remote-address:
          127.0.0.1:4506
      send-q:
          0
      state:
          TIME-WAIT
      user:
          0
    |_
      ----------
      inode:
          985
      local-address:
          [::]:22
      program:
          sshd
      proto:
          tcp
      recv-q:
          0
      remote-address:
          [::]:*
      send-q:
          128
      state:
          LISTEN
      user:
          0
192.168.11.132:
    |_
      ----------
      inode:
          26729
      local-address:
          127.0.0.1:323
      program:
          chronyd
      proto:
          udp
      recv-q:
          0
      remote-address:
          0.0.0.0:*
      send-q:
          0
      user:
          0
    |_
      ----------
      inode:
          26730
      local-address:
          [::1]:323
      program:
          chronyd
      proto:
          udp
      recv-q:
          0
      remote-address:
          [::]:*
      send-q:
          0
      user:
          0
    |_
      ----------
      inode:
          28958
      local-address:
          0.0.0.0:22
      program:
          sshd
      proto:
          tcp
      recv-q:
          0
      remote-address:
          0.0.0.0:*
      send-q:
          128
      state:
          LISTEN
      user:
          0

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

[root@master ~]# salt '*' network.ping baidu.com

192.168.11.120:
    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=64.9 ms
    64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=128 time=82.1 ms
    64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=3 ttl=128 time=133 ms
    64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=4 ttl=128 time=66.9 ms
    
    --- baidu.com ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3005ms
    rtt min/avg/max/mdev = 64.855/86.676/132.934/27.525 ms
192.168.11.132:
    PING baidu.com (220.181.38.148) 56(84) bytes of data.
    64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=128 time=77.7 ms
    64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=128 time=96.0 ms
    64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=128 time=144 ms
    64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=4 ttl=128 time=94.3 ms
    
    --- baidu.com ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3005ms
    rtt min/avg/max/mdev = 77.741/102.986/143.860/24.657 ms

2.1.17 network.reverse_ip
返回一个指定的IP地址的反向地址

[root@master ~]#  salt '*' network.reverse_ip 192.168.11.132
192.168.11.120:
    132.11.168.192.in-addr.arpa
192.168.11.132:
    132.11.168.192.in-addr.arpa

2.2 SaltStack常用模块之service

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

[root@master ~]#  salt '*' service.available sshd
192.168.11.120:
    True
192.168.11.132:
    True
[root@master ~]# salt '*' service.available vsftpd
192.168.11.120:
    False
192.168.11.132:
    False

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

[root@master ~]#  salt '*' service.get_all
192.168.11.120:
    - NetworkManager
    - NetworkManager-dispatcher
    - NetworkManager-wait-online
    - auditd
    - autovt@
    - basic.target
    - blk-availability
    - bluetooth.target
    - boot-complete.target
    - chrony-dnssrv@
    - chrony-dnssrv@.timer
    - chrony-wait
    - chronyd
    - console-getty
    - container-getty@
    - cpupower
    - crond
.......

2.2.3 service.disabled
检查指定服务是否开机不自动启动

[root@master ~]# salt '*' service.disabled httpd
192.168.11.120:
    True
192.168.11.132:
    True

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

[root@master ~]# salt '*' service.enabled httpd
192.168.11.120:
    False
192.168.11.132:
    False

2.2.5 service.disable
设置指定服务开机不自动启动

[root@master ~]# salt '*' service.disable httpd
192.168.11.120:
    False
192.168.11.132:
    True
[root@master ~]# salt '192.168.11.132' service.disable httpd
192.168.11.132:
    True

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

[root@master ~]#  salt '192.168.11.132' service.enable httpd
192.168.11.132:
    True
[root@master ~]#  salt '192.168.11.132' service.enabled httpd
192.168.11.132:
    True

2.2.7 service.reload
重新加载指定服务

[root@master ~]# salt '192.168.11.132' service.reload httpd
192.168.11.132:
    True

2.2.8 service.stop
停止指定服务

[root@master ~]# salt '192.168.11.132' service.stop httpd
192.168.11.132:
    True

2.2.9 service.start
启动指定服务

[root@master ~]# salt '192.168.11.132' service.start httpd
192.168.11.132:
    True

2.2.10 service.restart
重启指定服务

[root@master ~]# salt '192.168.11.132' service.restart httpd
192.168.11.132:
    True

2.2.11 service.status
查看指定服务的状态

[root@master ~]# salt '192.168.11.132' service.status httpd
192.168.11.132:
    True

2.3 SaltStack常用模块之pkg

2.3.1 pkg.download
只下载软件包但不安装
此功能将会下载指定的软件包,但是需要在minion端安装yum-utils,可以使用 cmd.run 进行远程安装

[root@master ~]#  salt '192.168.11.132' pkg.download wget
192.168.11.132:
    ----------
    wget:
        /var/cache/yum/packages/wget-1.19.5-10.el8.x86_64.rpm

2.3.2 pkg.file_list
列出指定包或系统中已安装的所有包的文件

//列出已安装的apache软件包提供的所有文件
[root@master ~]# salt '192.168.11.132' pkg.file_list httpd
192.168.11.132:
    ----------
    errors:
    files:
        - /etc/httpd/conf
        - /etc/httpd/conf.d/autoindex.conf
        - /etc/httpd/conf.d/userdir.conf
        - /etc/httpd/conf.d/welcome.conf
        - /etc/httpd/conf.modules.d
        - /etc/httpd/conf.modules.d/00-base.conf
        - /etc/httpd/conf.modules.d/00-dav.conf
        - /etc/httpd/conf.modules.d/00-lua.conf
        - /etc/httpd/conf.modules.d/00-mpm.conf
        - /etc/httpd/conf.modules.d/00-optional.conf
        - /etc/httpd/conf.modules.d/00-proxy.conf
        - /etc/httpd/conf.modules.d/00-systemd.conf
        - /etc/httpd/conf.modules.d/01-cgi.conf
        - /etc/httpd/conf.modules.d/README
        - /etc/httpd/conf/httpd.conf
        - /etc/httpd/conf/magic
        - /etc/httpd/logs
        - /etc/httpd/modules
        - /etc/httpd/run
        - /etc/httpd/state
        - /etc/logrotate.d/httpd
        - /etc/sysconfig/htcacheclean
        - /run/httpd
.......
//当不提供参数时,将会列出当前系统中所有已安装软件的文件列表
[root@master ~]# salt '192.168.11.132' pkg.file_list 
192.168.11.132:
    ----------
    errors:
    files:
        VALUE_TRIMMED

2.3.3 pkg.group_info
查看包组的信息

[root@master ~]# salt '192.168.11.132' pkg.group_info 'Development Tools'
192.168.11.132:
    ----------
    conditional:
    default:
        - asciidoc
        - byacc
        - ctags
        - diffstat
        - elfutils-libelf-devel
        - git
        - intltool
        - jna
        - ltrace
        - patchutils
        - perl-Fedora-VSP
        - perl-Sys-Syslog
        - perl-generators
        - pesign
        - source-highlight
        - systemtap
        - valgrind
        - valgrind-devel
    description:
        A basic development environment.
    group:
        Development Tools
    id:
        None
    mandatory:
        - autoconf
        - automake
        - binutils
        - bison
        - flex
        - gcc
        - gcc-c++
        - gdb
        - glibc-devel
        - libtool
        - make
        - pkgconf
        - pkgconf-m4
        - pkgconf-pkg-config
        - redhat-rpm-config
        - rpm-build
        - rpm-sign
        - strace
    optional:
        - cmake
        - expect
        - rpmdevtools
        - rpmlint
    type:
        package group

2.3.4 pkg.group_list
列出系统中所有的包组

[root@master ~]# salt '192.168.11.132' pkg.group_list
192.168.11.132:
    ----------
    available:
        - Backup Client
        - base-x
        - Conflicts AppStream
        - Container Management
        - Debugging Tools
        - Desktop Debugging and Performance Tools
        - .NET Core Development
        - FTP Server
        - GNOME Applications
        - Graphics Creation Tools
        - Guest Agents
        - Guest Desktop Agents
        - Input Methods
        - Internet Applications
        - Internet Browser
        - Java Platform
        - Legacy X Window System Compatibility
        - Multimedia
        - Office Suite and Productivity
        - Atomic Host ostree support
        - KVM platform specific packages
        - Hyper-v platform specific packages
        - Printing Client
        - Remote Desktop Clients
        - RPM Development Tools
        - TeX formatting system
        - Virtualization Client
        - Virtualization Hypervisor
        - Virtualization Platform
        - Virtualization Tools
        - Basic Web Server
        - Additional Development
        - Anaconda tools
        - Base
        - Conflicts BaseOS
        - Development Tools
        - Dial-up Networking Support
        - File and Storage Server
        - Fonts
        - GNOME
        - Graphical Administration Tools
        - Hardware Monitoring Utilities
        - Hardware Support
        - Headless Management
        - Infiniband Support
        - Large Systems Performance
        - Legacy UNIX Compatibility
        - Mail Server
        - Mainframe Access
        - Network File System Client
        - Network Servers
        - Networking Tools
        - Common NetworkManager submodules
        - Performance Tools
        - Platform Development
        - Python Web
        - Remote Management for Linux
        - Scientific Support
        - Security Tools
        - Server product core
        - Smart Card Support
        - Windows File Server
        - Standard
        - System Tools
        - Workstation product core
    available environments:
        - Server with GUI
        - Server
        - Workstation
        - Virtualization Host
        - Custom Operating System
    available languages:
        ----------
    installed:
        - VMware platform specific packages
        - Core
    installed environments:
        - Minimal Install

2.3.5 pkg.install
安装软件

[root@master ~]# salt '*' pkg.install wget
192.168.11.120:
    ----------
    wget:
        ----------
        new:
            1.19.5-10.el8
        old:
192.168.11.132:
    ----------
    wget:
        ----------
        new:
            1.19.5-10.el8
        old:

2.3.6 pkg.list_downloaded
列出已下载到本地的软件包

[root@master ~]# salt '*' pkg.list_downloaded
192.168.11.120:
    ----------
192.168.11.132:
    ----------

2.3.7 pkg.list_pkgs
以字典的方式列出当前已安装的软件包

[root@master ~]#  salt '192.168.11.132' pkg.list_pkgs
192.168.11.132:
    ----------
    NetworkManager:
        1:1.30.0-0.3.el8
    NetworkManager-libnm:
        1:1.30.0-0.3.el8
    NetworkManager-team:
        1:1.30.0-0.3.el8
    NetworkManager-tui:
        1:1.30.0-0.3.el8
    abattis-cantarell-fonts:
        0.0.25-4.el8
    acl:
        2.2.53-1.el8
    adwaita-cursor-theme:
        3.28.0-2.el8
    adwaita-icon-theme:
        3.28.0-2.el8
    apr:
        1.6.3-11.el8
    apr-util:
        1.6.1-6.el8
    apr-util-bdb:
        1.6.1-6.el8
    apr-util-openssl:
        1.6.1-6.el8
    at-spi2-atk:
        2.26.2-1.el8
    at-spi2-core:
        2.28.0-1.el8
    atk:
        2.28.1-1.el8
    audit:
        3.0-0.17.20191104git1c2f876.el8
    audit-libs:
        3.0-0.17.20191104git1c2f876.el8
    authselect:
        1.2.2-1.el8
    authselect-libs:
        1.2.2-1.el8
    avahi-libs:
        0.7-20.el8
    basesystem:
        11-5.el8
    bash:
        4.4.19-12.el8
    bash-completion:
        1:2.7-5.el8
    bind-export-libs:
        32:9.11.20-6.el8
    biosdevname:
        0.7.3-2.el8
    brotli:
        1.0.6-2.el8
    bzip2-libs:
        1.0.6-26.el8
    c-ares:
        1.13.0-5.el8
    ca-certificates:
        2020.2.41-80.0.el8_2
    cairo:
        1.15.12-3.el8
    cairo-gobject:
        1.15.12-3.el8
    centos-gpg-keys:
        1:8-2.el8
    centos-logos-httpd:
        85.5-1.el8
    centos-stream-release:
        8.4-1.el8
    centos-stream-repos:
        8-2.el8
    chkconfig:
        1.13-2.el8
    chrony:
        3.5-1.el8
    colord-libs:
        1.4.2-1.el8
    coreutils:
        8.30-8.el8
    coreutils-common:
        8.30-8.el8
    cpio:
        2.12-9.el8
    cracklib:
        2.9.6-15.el8
    cracklib-dicts:
        2.9.6-15.el8
    cronie:
        1.5.2-4.el8
    cronie-anacron:
        1.5.2-4.el8
    crontabs:
        1.11-16.20150630git.el8
    crypto-policies:
        20200713-1.git51d1222.el8
    crypto-policies-scripts:
        20200713-1.git51d1222.el8
    cryptsetup-libs:
        2.3.3-2.el8
......

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

[root@master ~]# salt '192.168.11.132' pkg.owner /usr/sbin/apachectl
192.168.11.132:
    httpd
[root@master ~]# salt '192.168.11.132' pkg.owner /usr/sbin/apachectl /etc/httpd/conf/httpd.conf
192.168.11.132:
    ----------
    /etc/httpd/conf/httpd.conf:
        httpd
    /usr/sbin/apachectl:
        httpd

2.3.9 pkg.remove
卸载指定软件

[root@master ~]# salt '192.168.11.132' cmd.run 'rpm -qa|grep wget'
192.168.11.132:
    wget-1.19.5-10.el8.x86_64

2.3.10 pkg.upgrade

[root@master ~]# salt '192.168.11.132' pkg.upgrade name=openssl
升级系统中所有的软件包或升级指定的软件包
192.168.11.132:
    ----------
    openssl:
        ----------
        new:
            1:1.1.1k-1.el8
        old:
            1:1.1.1g-11.el8
    openssl-libs:
        ----------
        new:
            1:1.1.1k-1.el8
        old:
            1:1.1.1g-11.el8
 //若想升级系统中所有的软件包则把 name 参数去掉即可

2.4 SaltStack常用模块之state

2.4.1 state.show_highstate
显示当前系统中有哪些高级状态


2.4.2 state.highstate
执行高级状态


2.4.3 state.show_state_usage
2.4.4 state.show_top
2.4.5 state.top
2.4.6 state.show_sls
2.5 SaltStack常用模块之salt-cp

上一篇:centos7 安装gitlab


下一篇:126、C++中类成员的访问权限和继承权限问题