SaltStack常用的模块

SaltStack常用的模块

1.Saltstack模块介绍

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

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

查看所有module列表:

[root@master ~]# salt 'minion' test.ping
minion:
    True
[root@master ~]# salt 'minion' sys.list_modules
minion:
    - acl
    - aliases
    - alternatives
    - apache
    - archive
    - artifactory
    - baredoc
    - beacons
    - bigip
    - btrfs
    - buildout
    - chroot
    - cloud
    - cmd
    - composer
    - config
    - consul
    - container_resource
    - cp
    - cron
略。。。。。。
[root@master ~]#

查看指定module的所有function

[root@master ~]# salt 'master' sys.list_functions cloud
master:
    - cloud.action
    - cloud.create
    - cloud.destroy
    - cloud.full_query
    - cloud.get_instance
    - cloud.has_instance
    - cloud.list_images
    - cloud.list_locations
    - cloud.list_sizes
    - cloud.map_run
    - cloud.network_create
    - cloud.network_list
    - cloud.profile
    - cloud.query
    - cloud.select_query
    - cloud.virtual_interface_create
    - cloud.virtual_interface_list
    - cloud.volume_attach
    - cloud.volume_create
    - cloud.volume_delete
    - cloud.volume_detach
    - cloud.volume_list
[root@master ~]# 

查看指定module的用法

[root@master ~]# salt 'minion' sys.doc cloud
cloud.action:

    Execute a single action on the given provider/instance

    CLI Example:

        salt minionname cloud.action start instance=myinstance
        salt minionname cloud.action stop instance=myinstance
        salt minionname cloud.action show_image provider=my-ec2-config image=ami-1624987f
        略。。。。。。

saltstack默认也支持一次执行多个module,module之间通过逗号隔开–args-separator=@即可

[root@master ~]# salt 'minion' test.echo,cmd.run,service.status hello,hostname,salt-minion
minion:
    ----------
    cmd.run:
        node1
    service.status:
        True
    test.echo:
        hello
[root@master ~]# 

2.saltstack常用的模块(network)

2.1.network.active_tcp

返回所有活动的tcp连接

[root@master ~]# salt 'm*' network.active_tcp
master:
    ----------
    0:
        ----------
        local_addr:
            192.168.100.148
        local_port:
            4505
        remote_addr:
            192.168.100.148
        remote_port:
            49912
    1:
        ----------
        local_addr:
            192.168.100.148
        local_port:
            4505
        remote_addr:
            192.168.100.149
        remote_port:
            35982
    2:
        ----------
        local_addr:
            192.168.100.148
        local_port:
            49912
        remote_addr:
            192.168.100.148
        remote_port:
            4505
    3:
        ----------
        local_addr:
            192.168.100.148
        local_port:
            22
        remote_addr:
            192.168.100.1
        remote_port:
            65401
minion:
    ----------
    0:
        ----------
        local_addr:
            192.168.100.149
        local_port:
            22
        remote_addr:
            192.168.100.1
        remote_port:
            65406
    1:
        ----------
        local_addr:
            192.168.100.149
        local_port:
            35982
        remote_addr:
            192.168.100.148
        remote_port:
            4505
[root@master ~]# 
2.2.network.calc_net

通过IP和子网掩码计算处网段

[root@master ~]# salt 'm*' network.calc_net 192.168.100.150 255.255.0.0
master:
    192.168.0.0/16
minion:
    192.168.0.0/16
[root@master ~]# 
[root@master ~]# salt '*' network.calc_net 192.168.69.202 255.255.255.240
minion:
    192.168.69.192/28
master:
    192.168.69.192/28
2.4.network.connect

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

[root@master ~]# salt 'm*' network.connect www.baidu.com 80
minion:
    ----------
    comment:
        Successfully connected to www.baidu.com (36.152.44.96) on tcp port 80
    result:
        True
master:
    ----------
    comment:
        Successfully connected to www.baidu.com (36.152.44.95) on tcp port 80
    result:
        True
[root@master ~]# 
[root@master ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port  Peer Address:Port                     Process                      
LISTEN 0      128          0.0.0.0:22         0.0.0.0:*                                                     
LISTEN 0      128          0.0.0.0:4505       0.0.0.0:*                                                     
LISTEN 0      128          0.0.0.0:4506       0.0.0.0:*                                                     
LISTEN 0      128             [::]:22            [::]:*                                                     
LISTEN 0      128                *:80               *:*                                                     
[root@master ~]# salt 'm*' network.connect 192.168.100.148 4505
minion:
    ----------
    comment:
        Successfully connected to 192.168.100.148 (192.168.100.148) on tcp port 4505
    result:
        True
master:
    ----------
    comment:
        Successfully connected to 192.168.100.148 (192.168.100.148) on tcp port 4505
    result:
        True
[root@master ~]# 
2.5.network.default_route

查看默认路由

[root@master ~]# salt 'm*' network.default_route
minion:
    |_
      ----------
      addr_family:
          inet
      destination:
          0.0.0.0
      flags:
          UG
      gateway:
          192.168.100.2
      interface:
          ens33
      netmask:
          0.0.0.0
master:
    |_
      ----------
      addr_family:
          inet
      destination:
          0.0.0.0
      flags:
          UG
      gateway:
          192.168.100.2
      interface:
          ens33
      netmask:
          0.0.0.0
[root@master ~]# 
2.6.network.get_fqdn

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

[root@master ~]# salt 'm*' network.get_fqdn
minion:
    node1
master:
    master
[root@master ~]# 

获取主机名

[root@master ~]# salt 'm*' network.get_hostname
minion:
    node1
master:
    master
[root@master ~]# 
2.7.network.get_route

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

[root@master ~]# salt 'm*' network.get_route 192.168.100.148
minion:
    ----------
    destination:
        192.168.100.148
    gateway:
        None
    interface:
        ens33
    source:
        192.168.100.149
master:
    ----------
    destination:
        192.168.100.148
    gateway:
        None
    interface:
        lo
    source:
        192.168.100.148
[root@master ~]# 
2.8.network.hw_addr

返回指定网卡的MAC地址

[root@master ~]# salt 'm*' network.hw_addr ens33
minion:
    00:0c:29:70:da:64
master:
    00:0c:29:fd:cd:90
[root@master ~]# 
2.9.network.ifacestartswith

从特定CIDR检索接口名称

[root@master ~]# salt 'm*' network.ifacestartswith 192.168.100.148
master:
    - ens33
minion:
[root@master ~]# 
2.10.network.in_subnet

判断当前主机是否在某一个网内

[root@master ~]# salt 'm*' network.in_subnet 192.168.100.0/24
master:
    True
minion:
    True
[root@master ~]#
2.11.network.interface

返回指定网卡的信息

[root@master ~]# salt 'm*' network.interface ens33
minion:
    |_
      ----------
      address:
          192.168.100.149
      broadcast:
          192.168.100.255
      label:
          ens33
      netmask:
          255.255.255.0
master:
    |_
      ----------
      address:
          192.168.100.148
      broadcast:
          192.168.100.255
      label:
          ens33
      netmask:
          255.255.255.0
[root@master ~]# 
2.12.network.interface_ip

返回指定网卡的IP地址

[root@master ~]# salt 'm*' network.interface_ip ens33
minion:
    192.168.100.149
master:
    192.168.100.148
[root@master ~]# 
2.13.network.interfaces

返回当前系统中所有的网卡信息

[root@master ~]# salt 'm*' network.interfaces
minion:
    ----------
    ens33:
        ----------
        hwaddr:
            00:0c:29:70:da:64
        inet:
            |_
              ----------
              address:
                  192.168.100.149
              broadcast:
                  192.168.100.255
              label:
                  ens33
              netmask:
                  255.255.255.0
        inet6:
            |_
              ----------
              address:
                  fe80::fdbf:aff7:d636:5069
              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
master:
    ----------
    ens33:
        ----------
        hwaddr:
            00:0c:29:fd:cd:90
        inet:
            |_
              ----------
              address:
                  192.168.100.148
              broadcast:
                  192.168.100.255
              label:
                  ens33
              netmask:
                  255.255.255.0
        inet6:
            |_
              ----------
              address:
                  fe80::cfeb:3fe4:99b:3ec2
              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
[root@master ~]# 
2.14.network.ip_addrs

返回一个IPv4的地址列表

该函数将会忽略掉127.0.0.1的地址

[root@master ~]# salt 'm*' network.ip_addrs
minion:
    - 192.168.100.149
master:
    - 192.168.100.148
[root@master ~]#
2.15.network.netstat

返回所有打开的端口和状态

[root@master ~]# salt 'm*' network.netstat
master:
    |_
      ----------
      inode:
          30448
      local-address:
          192.168.100.148%ens33:68
      program:
          NetworkManager
      proto:
          udp
      recv-q:
          0
      remote-address:
          192.168.100.254:67
      send-q:
          0
      user:
          0
    |_
      ----------
      inode:
          28710
      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
 略。。。。。。
[root@master ~]# 
2.16.network.ping

使用ping命令测试到某主机的连通性, 这里和window上的ping差不多

[root@master ~]# salt 'minion' network.ping baidu.com
minion:
    PING baidu.com (220.181.38.251) 56(84) bytes of data.
    64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=1 ttl=128 time=85.0 ms
    64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=2 ttl=128 time=57.9 ms
    64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=3 ttl=128 time=49.5 ms
    64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=4 ttl=128 time=53.5 ms
    
    --- baidu.com ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3005ms
    rtt min/avg/max/mdev = 49.548/61.492/85.045/13.916 ms
    
[root@master ~]# salt 'minion' network.ping 192.168.100.149
minion:
    PING 192.168.100.149 (192.168.100.149) 56(84) bytes of data.
    64 bytes from 192.168.100.149: icmp_seq=1 ttl=64 time=0.026 ms
    64 bytes from 192.168.100.149: icmp_seq=2 ttl=64 time=0.041 ms
    64 bytes from 192.168.100.149: icmp_seq=3 ttl=64 time=0.047 ms
    64 bytes from 192.168.100.149: icmp_seq=4 ttl=64 time=0.053 ms
    
    --- 192.168.100.149 ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3093ms
    rtt min/avg/max/mdev = 0.026/0.041/0.053/0.012 ms
[root@master ~]# 
2.17.network.reverse_ip

返回一个指定的IP地址的反向地址

[root@master ~]# salt 'm*' network.reverse_ip 192.168.100.148
minion:
    148.100.168.192.in-addr.arpa
master:
    148.100.168.192.in-addr.arpa
[root@master ~]# 

3.Saltstack常用的模块service

3.1.service.available

判断指定的服务器是否可用

[root@master ~]# salt 'm*' service.available sshd
minion:
    True
master:
    True
[root@master ~]# salt 'm*' service.available cmd
minion:
    False
master:
    False
[root@master ~]# salt 'm*' service.available cloud
minion:
    False
master:
    False
[root@master ~]# salt 'm*' service.available vsftpd
minion:
    False
master:
    False
[root@master ~]# 
3.2.service.get_all

获取所有正在运行的服务

[root@master ~]# salt 'minion' service.get_all
minion:
    - 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
略。。。。。。
[root@master ~]# 
3.3.service.disabled

检查指定服务是否开机不自启动

[root@master ~]# salt 'minion' service.disabled httpd
minion:
    False
[root@master ~]# 
3.4.servce.enabled

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

[root@master ~]# salt 'minion' service.enabled httpd
minion:
    True
[root@master ~]# 
3.5.service.disable

设置指定服务开机不自启动

[root@master ~]# salt 'minion' service.disable httpd
minion:
    True
[root@master ~]# salt 'minion' service.enabled httpd
minion:
    False
[root@master ~]# 
3.6.service.enable

设置指定服务开机自启动

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

重新加载指定服务

[root@master ~]# salt 'minion' service.reload httpd
minion:
    True
[root@master ~]# 
3.8.service.stop

停止指定服务

[root@master ~]# salt 'minion' service.stop httpd
minion:
    True
[root@master ~]#
[root@node1 ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port  Peer Address:Port                     Process                      
LISTEN 0      128          0.0.0.0:22         0.0.0.0:*                                                     
LISTEN 0      128             [::]:22            [::]:*                                                     
[root@node1 ~]# 
3.9.service.start

启动指定服务

[root@master ~]# salt 'minion' service.start httpd
minion:
    True
[root@master ~]#
[root@node1 ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port  Peer Address:Port                     Process                      
LISTEN 0      128          0.0.0.0:22         0.0.0.0:*                                                     
LISTEN 0      128                *:80               *:*                                                     
LISTEN 0      128             [::]:22            [::]:*                                                     
[root@node1 ~]# 
3.10.service.restart

重启指定服务

[root@master ~]# salt 'minion' service.restart httpd
minion:
    True
[root@master ~]# 
3.11.service.status

查看指定服务的状态

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

4.Saltstack常用模块(pkg)

4.1.pkg.download

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

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

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

[root@master ~]# salt 'minion' pkg.file_list httpd
minion:
    ----------
    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
略。。。。。。
[root@master ~]# 

当不提供参数时,将会列出当前系统总所有一按安装的文件列表

[root@master ~]# salt 'minion' pkg.file_list
minion:
    ----------
    errors:
    files:
        VALUE_TRIMMED
[root@master ~]# 
4.3.pkg.group_info

查看包组的信息

[root@master ~]# salt 'minion' pkg.group_info 'Development Tools'
minion:
    ----------
    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
[root@master ~]# 
4.4.pkg.group_list

列出系统中的所有的包组

[root@master ~]# salt 'minion' pkg.file_list
minion:
    ----------
    errors:
    files:
        VALUE_TRIMMED
[root@master ~]# 
[root@master ~]# salt 'minion' pkg.group_info 'Development Tools'
minion:
    ----------
    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
[root@master ~]# 
[root@master ~]# salt 'minion' pkg.group_list
minion:
    ----------
    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
[root@master ~]# 
4.5.pkg.install

安装软件

[root@master ~]# salt 'minion' pkg.install wget
minion:
    ----------
    wget:
        ----------
        new:
            1.19.5-10.el8
        old:
[root@master ~]# 
4.6.pkg.list_dowmloaded

列出已下载到本地的软件包

[root@master ~]# salt 'master' pkg.list_downloaded
master:
    ----------
[root@master ~]# 
4.7.pkg.list_pkgs

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

[root@master ~]# salt 'minion' pkg.list_pkgs
minion:
    ----------
    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
略。。。。。。
[root@master ~]# 
4.8.pkg.owner

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

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

卸载指定软件

如果要卸载多个文件,中间要用逗号隔开

[root@master ~]# salt 'minion' pkg.remove wget
minion:
    ----------
    wget:
        ----------
        new:
        old:
            1.19.5-10.el8
[root@master ~]# 
4.10.pkg.upgrade

升级系统中所有的软件包或升级指定的软件包

若想升级系统中所有的软件包,则把name参数去掉即可

[root@master ~]# salt 'minion' pkg.upgrade name=openssl
minion:
    ----------
    openssl:
        ----------
        new:
            1:1.1.1k-4.el8
        old:
            1:1.1.1g-11.el8
    openssl-libs:
        ----------
        new:
            1:1.1.1k-4.el8
        old:
            1:1.1.1g-11.el8
[root@master ~]# 

5.saltstack常用模块(state)

5.1.stat.show_highstate

显示当前系统中有那些高级状态

[root@master salt]# salt 'minion' state.show_highstate 
minion:
    ----------
    apache-install:
        ----------
        __env__:
            base
        __sls__:
            web.apache.apache
        pkg:
            |_
              ----------
              name:
                  httpd
            - installed
            |_
              ----------
              order:
                  10000
    apache-service:
        ----------
        __env__:
            base
        __sls__:
            web.apache.apache
        service:
            |_
              ----------
              name:
                  httpd
            |_
              ----------
              enable:
                  True
            - running
            |_
              ----------
              order:
                  10001
[root@master salt]# 
5.2.state.highstate

执行高级状态

[root@master salt]# salt 'minion' state.highstate web.apache.apache
minion:
----------
          ID: apache-install
    Function: pkg.installed
        Name: httpd
      Result: True
     Comment: All specified packages are already installed
     Started: 04:28:55.503214
    Duration: 504.605 ms
     Changes:   
----------
          ID: apache-service
    Function: service.running
        Name: httpd
      Result: None
     Comment: Service httpd is set to start
     Started: 04:28:56.013212
    Duration: 56.958 ms
     Changes:   

Summary for minion
------------
Succeeded: 2 (unchanged=1)
Failed:    0
------------
Total states run:     2
Total run time: 561.563 ms
[root@master salt]# 
5.3.state.show_state_usage

显示当前系统中的高级状态执行情况

[root@master ~]# salt 'minion' state.show_state_usage
minion:
    ----------
    base:
        ----------
        count_all:
            2
        count_unused:
            1
        count_used:
            1
        unused:
            - top
        used:
            - web.apache.apache
    dev:
        ----------
        count_all:
            0
        count_unused:
            0
        count_used:
            0
        unused:
        used:
    prod:
        ----------
        count_all:
            0
        count_unused:
            0
        count_used:
            0
        unused:
        used:
    test:
        ----------
        count_all:
            0
        count_unused:
            0
        count_used:
            0
        unused:
        used:
[root@master ~]# 
5.4.state.show_top

返回minion将用于highstate的顶级数据

[root@master ~]# salt 'minion' state.show_top
minion:
    ----------
    base:
        - web.apache.apache
[root@master ~]# 
5.5.state.top

执行指定的top file,而不是默认的

[root@master ~]# salt 'minion' state.top wget.sls
minion:
----------
          ID: states
    Function: no.None
      Result: False
     Comment: No Top file or master_tops data matches found. Please see master log for details.
     Changes:   

Summary for minion
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:   0.000 ms
ERROR: Minions returned with non-zero exit code
[root@master ~]# 
5.6.state.show_sls

显示 master 上特定sls或sls文件列表中的状态数据

[root@master ~]# salt 'minion' state.show_sls web.apache.apache
minion:
    ----------
    apache-install:
        ----------
        __env__:
            base
        __sls__:
            web.apache.apache
        pkg:
            |_
              ----------
              name:
                  httpd
            - installed
            |_
              ----------
              order:
                  10000
    apache-service:
        ----------
        __env__:
            base
        __sls__:
            web.apache.apache
        service:
            |_
              ----------
              name:
                  httpd
            |_
              ----------
              enable:
                  True
            - running
            |_
              ----------
              order:
                  10001
[root@master ~]# 

6.saltstack常用模块(user)

6.1.user.add

添加用户到节点

[root@master ~]# salt 'minion' user.add sb
minion:
    True
[root@master ~]#
6.2.user.chfullname

改变用户全名

[root@master ~]# salt 'minion' user.chfullname sb "qiangzi"
minion:
    True
[root@master ~]# 
6.3.user.chuid

更改用户UID

[root@master ~]# salt 'minion' user.chuid sb 1314
minion:
    True
[root@master ~]# 
[root@node1 ~]# id sb
uid=1314(sb) gid=1000(sb) 组=1000(sb)
[root@node1 ~]# 
6.4.user.chgid

更改用户GID

[root@master ~]# salt 'minion' user.chgid sb 999
minion:
    True
[root@master ~]# salt 'minion' cmd.run 'tail -1 /etc/passwd'
minion:
    sb:x:1314:999:qiangzi:/home/sb:/bin/bash
[root@master ~]# 
6.5.user.chgroups

更改用户属组,追加指定用户组

[root@master ~]#  salt 'minion' user.chgroups sb root true
minion:
    True
[root@master ~]#  salt 'minion' cmd.run 'id sb'
minion:
    uid=1314(sb) gid=999(input) groups=999(input),0(root)
[root@master ~]# 
6.6.user.chhome

更改用户家目录,拷贝原家目录到新家目录

[root@master ~]# salt 'minion' user.chhome sb /home/sh 
minion:
    True
[root@master ~]# 
[root@master ~]# salt 'minion' cmd.run 'tail -1 /etc/passwd'
minion:
    sb:x:1314:999:qiangzi:/home/sh:/bin/bash
[root@master ~]# 
6.7.user.info

返回用户信息

[root@master ~]# salt 'minion' user.info sb
minion:
    ----------
    fullname:
        qiangzi
    gid:
        999
    groups:
        - input
        - root
    home:
        /home/sh
    homephone:
    name:
        sb
    other:
    passwd:
        x
    roomnumber:
    shell:
        /bin/bash
    uid:
        1314
    workphone:
[root@master ~]# 
6.8.user.getent

返回所有系统用户信息

[root@master ~]# salt 'minion' user.getent
minion:
    |_
      ----------
      fullname:
          root
      gid:
          0
      groups:
          - root
      home:
          /root
      homephone:
      name:
          root
      other:
      passwd:
          x
      roomnumber:
      shell:
          /bin/bash
      uid:
          0
      workphone:
    |_
      ----------
      fullname:
          bin
      gid:
          1
      groups:
          - bin
      home:
          /bin
      homephone:
      name:
          bin
      other:
      passwd:
          x
      roomnumber:
      shell:
          /sbin/nologin
      uid:
          1
      workphone:
    |_
      ----------
 略。。。。。。
[root@master ~]# 
6.9.user.rename

更改用户名

[root@master ~]# salt 'minion' user.rename shuaige shen
minion:
    False
[root@master ~]# salt 'minion' user.info shen
minion:
    ----------
    fullname:
        qiangzi
    gid:
        999
    groups:
        - input
        - root
    home:
        /home/sh
    homephone:
    name:
        shen
    other:
    passwd:
        x
    roomnumber:
    shell:
        /bin/bash
    uid:
        1314
    workphone:
[root@master ~]# 
6.10.user.delete

删除用户

[root@master ~]# salt 'minion' user.delete shen
minion:
    True
[root@master ~]# 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lfei5120

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值