SaltStack常用的模块

Posted 码出未来_远

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SaltStack常用的模块相关的知识,希望对你有一定的参考价值。

SaltStack常用的模块

文章目录

SaltStack模块介绍

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

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

[root@master ~]# salt 'minion' sys.list_modules
minion:
    - acl
    - aliases
    - alternatives
    - ansible
    - archive
    - artifactory
    - baredoc
    - beacons
    - bigip
此处省略N行

查看指定module的所有function

[root@master ~]# salt 'minion' sys.list_functions cmd
minion:
    - 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

查看指定module的用法

[root@master ~]# salt 'minion' 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.

    CLI Example:

        salt '*' cmd.exec_code ruby 'puts "cheese"' 
...此处省略N行...

SaltStack默认也支持一次执行多个Module,Module之间通过逗号隔开,默认传参之间也是用逗号分隔,也支持指定传参分隔符号–args-separator=@即可

[root@master ~]# salt 'minion' test.echo,cmd.run,service.status test,date,salt-minion
minion:
    ----------
    cmd.run:
        Tue Jul  6 18:12:15 CST 2021
    service.status:
        True
    test.echo:
        test

SaltStack常用模块

SaltStack常用模块之network

network.active_tcp

返回所有活动的tcp连接

[root@master ~]# salt '*' network.active_tcp
minion:
    ----------
    0:
        ----------
        local_addr:
            192.168.207.137
        local_port:
            22
        remote_addr:
            192.168.207.1
        remote_port:
            57062
    1:
        ----------
        local_addr:
            192.168.207.137
        local_port:
            43948
        remote_addr:
            192.168.207.131
        remote_port:
            4505

network.calc_net

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

[root@master ~]# salt '*' network.calc_net 192.168.207.131 255.255.255.0
minion:
    192.168.207.0/24
[root@master ~]# salt '*' network.calc_net 192.168.207.131 255.255.255.240
minion:
    192.168.207.128/28

network.connect

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

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

network.default_route

查看默认路由

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

network.get_fqdn

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

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

network.get_hostname

获取主机名

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

network.get_route

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

[root@master ~]# salt '*' network.get_route 192.168.207.155
minion:
    ----------
    destination:
        192.168.207.155
    gateway:
        None
    interface:
        ens33
    source:
        192.168.207.137

network.hw_addr

返回指定网卡的MAC地址

[root@master ~]# salt '*' network.hw_addr ens33
minion:
    00:0c:29:e1:7e:2b

network.ifacestartswith

从特定CIDR检索接口名称

[root@master ~]# salt '*' network.ifacestartswith 192.168;
minion:
    - ens33

network.in_subnet

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

[root@master ~]# salt '*' network.in_subnet 192.168.207.0/24 
minion:
    True

network.interface

返回指定网卡的信息

[root@master ~]# salt '*' network.interface ens33
minion:
    |_
      ----------
      address:
          192.168.207.137
      broadcast:
          192.168.207.255
      label:
          ens33
      netmask:
          255.255.255.0

network.interface_ip

返回指定网卡的IP地址

[root@master ~]# salt '*' network.interface_ip ens33
minion:
    192.168.207.137

network.interfaces

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

[root@master ~]# salt '*' network.interfaces
minion:
    ----------
    ens33:
        ----------
        hwaddr:
            00:0c:29:e1:7e:2b
        inet:
            |_
              ----------
              address:
                  192.168.207.137
              broadcast:
                  192.168.207.255
              label:
                  ens33
              netmask:
                  255.255.255.0
        inet6:
            |_
              ----------
              address:
                  fe80::d179:e52e:1aae:e40e
              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

network.ip_addrs

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

[root@master ~]# salt '*' network.ip_addrs
minion:
    - 192.168.207.137

network.netstat

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

[root@master ~]# salt '*' network.netstat
minion:
    |_
      ----------
      inode:
          28756
      local-address:
          192.168.207.137%ens33:68
      program:
          NetworkManager
      proto:
       省略。。。

network.ping

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

[root@master ~]# salt '*' network.ping baidu.com
minion:
    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=48.4 ms
    64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=128 time=55.3 ms
    64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=128 time=47.8 ms
    64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=4 ttl=128 time=54.4 ms
    
    --- baidu.com ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3004ms
    rtt min/avg/max/mdev = 47.757/51.436/55.254/3.406 ms

network.reverse_ip

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

[root@master ~]# salt '*' network.reverse_ip 192.168.207.130 
minion:
    130.207.168.192.in-addr.arpa

SaltStack常用模块之service

service.available

判断指定的服务是否可用

[root@master ~]# salt '*' service.available sshd
minion:
    True
[root@master ~]# salt '*' service.available tomcat
minion:
    False

service.get_all

获取所有正在运行的服务

[root@master ~]# salt '*' service.get_all
minion:
    - NetworkManager
    - NetworkManager-dispatcher
    - NetworkManager-wait-online
    - auditd
    - autovt@
省略。。。

service.disabled

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

[root@master ~]# salt '*' service.disabled sshd
minion:
    False

service.enabled

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

[root@master ~]# salt '*' service.enabled sshd
minion:
    True

service.disable

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

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

service.enable

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

[root@master ~]# salt '*' service.enable sshd
minion:
    True
[root@master ~]# salt '*' service.enabled sshd
minion:
    True

service.reload

重新加载指定服务

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

service.stop

停止指定服务

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

service.start

启动指定服务

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

service.restart

重启指定服务

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

service.status

查看指定服务的状态

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

SaltStack常用模块之pkg

pkg.download

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

[root@master ~]# salt '*' pkg.download nginx
minion:
    ----------
    nginx:
        /var/cache/yum/packages/nginx-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64.rpm			//下载好的软件放在这里

pkg.file_list

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

//列出已安装的apache软件包提供的所有文件
[root@master ~]# salt '*' pkg.file_list salt
...

        - /usr/share/fish/vendor_functions.d/salt-run.fish
        - /usr/share/fish/vendor_functions.d/salt-syndic.fish
        - /usr/share/fish/vendor_functions.d/salt.fish
        - /usr/share/fish/ven......
//当不提供参数时,将会列出当前系统中所有已安装软件的文件列表
[root@master ~]# salt '*' pkg.file_list
...

pkg.group_info

查看包组的信息

[root@master ~]# salt '*' pkg.group_info 'Development Tools'
minion:
    ----------
    conditional:
    default:
        - asciidoc
        - byacc
        - ctags
        - diffstat
        - elfutils-libelf-devel
        - git
        - intltool
        - jna
...

pkg.group_list

列出系统中所有的包组

[root@master ~]# salt '*' 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
.....
        - Custom Operating System
    available languages:
        ----------
    installed:
        - VMware platform specific packages
        - Core
    installed environments:
        - Minimal Install

pkg.install

安装软件

[root@master ~]# salt '*' pkg.install tree
minion:
    ----------
    tree:
        ----------
        new:
            1.7.0-15.el8
        old:

pkg.list_downloaded

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

[root@master ~]# salt '*' pkg.list_downloaded

pkg.list_pkgs

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

[root@master ~]# salt '*' pkg.group_list
minion:
    ----------
    available:
        - Backup Client
        - base-x
        - Conflicts AppStream
        - Container Management
        - Debugging Tools
        - Desktop Debugging and Performance Tools
        - .NET Core Development
...

pkg.owner

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

[root@master ~]# salt '*' pkg.owner /usr/sbin/accessdb
minion:
    man-db

pkg.remove

卸载指定软件

[root@master ~]# salt '*' cmd.run 'rpm -qa|grep tree'
minion:
    tree-1.7.0-15.el8.x86_64

pkg.upgrade

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

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

SaltStack常用模块之state

state.show_highstate

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

[root@master nginx]# salt 'minion' state.sls web.nginx.install
minion:
----------
          ID: nginx-install
    Function: pkg.installed
        Name: nginx
      Result: True
     Comment: The following packages were installed/updated: nginx
     Started: 22:13:51.451034
    Duration: 19264.591 ms
     Changes:   
              ----------
              dejavu-fonts-common:
                  ----------
                  new:
                      2.35-7.el8
                  old:
              dejavu-sans-fonts:
                  ----------
                  new:
                      2.35-7.el8
                  old:
              fontconfig:
                  ----------
                  new:
                      2.13.1-3.el8
                  old:
              fontpackages-filesystem:
                  ----------
                  new:
                      1.44-22.el8
                  old:
              gd:
                  ----------
                  new:
                      2.2.5-7.el8
                  old:
              jbigkit-libs:
                  ----------
                  new:
                      2.1-14.el8
                  old:
              libX11:
                  ----------
                  new:
                      1.6.8-4.el8
                  old:
              libX11-common:
                  ----------
                  new:
                      1.6.8-4.el8
                  old:
              libXau:
                  ----------
                  new:
                      1.0.9-3.el8
                  old:
              libXpm:
                  ----------
                  new:
                      3.5.12-8.el8
                  old:
              libjpeg-turbo:
                  ----------
                  new:
                      1.5.3-10.el8
                  old:
              libtiff:
                  ----------
                  new:
                      4.0.9-20.el8
                  old:
              libwebp:
                  ----------
                  new:
                      1.0.0-5.el8
                  old:
              libxcb:
                  ----------
                  new:
                      1.13.1-1.el8
                  old:
              nginx:
                  ----------
                  new:
                      1:1.14.1-9.module_el8.0.0+184+e34fea82
                  old:
              nginx-all-modules:
                  ----------
                  new:
                      1:1.14.1-9.module_el8.0.0+184+e34fea82
                  old:
              nginx-filesystem:
                  ----------
                  new:
                      1:1.14.1-9.module_el8.0.0+184+e34fea82
                  old:
              nginx-mod-http-image-filter:
                  ----------
                  new:
                      1:1.14.1-9.module_el8.0.0+184+e34fea82
                  old:
              nginx-mod-http-perl:
                  ----------
                  new:
                      1:1.14.1-9.module_el8.0.0+184+e34fea82
                  old:
              nginx-mod-http-xslt-filter:
                  ----------
                  new:
                      1:1.14.1-9.module_el8.0.0+184+e34fea82
                  old:
              nginx-mod-mail:
                  ----------
                  new:
                      1:1.14.1-9.module_el8.0.0+184+e34fea82
                  old:
              nginx-mod-stream:
                  ----------
                  new:
                      1:1.14.1-9.module_el8.0.0+184+e34fea82
                  old:
              perl-Carp:
                  ----------
                  new:
                      1.42-396.el8
                  old:
              perl-Data-Dumper:
                  ----------
                  new:
                      2.167-399.el8
                  old:
              perl-Digest:
                  ----------
                  new:
                      1.17-395.el8
                  old:
              perl-Digest-MD5:
                  ----------
                  new:
                      2.55-396.el8
                  old:
              perl-Encode:
                  ----------
                  new:
                      4:2.97-3.el8
                  old:
              perl-Errno:
                  ----------
                  new:
                      1.28-420.el8
                  old:
              perl-Exporter:
                  ----------
                  new:
                      5.72-396.el8
                  old:
              perl-File-Path:
                  ----------
                  new:
                      2.15-2.el8
                  old:
              perl-File-Temp:
                  ----------
                  new:
                      0.230.600-1.el8
                  old:
              perl-Getopt-Long:
                  ----------
                  new:
                      1:2.50-4.el8
                  old:
              perl-HTTP-Tiny:
                  ----------
                  new:
                      0.074-1.el8
                  old:
              perl-IO:
                  ----------
                  new:
                      1.38-420.el8
                  old:
              perl-IO-Socket-IP:
                  ----------
                  new:
                      0.39-5.el8
                  old:
              perl-IO-Socket-SSL:
                  ----------
                  new:
                      2.066-4.module_el8.4.0+517+be1595ff
                  old:
              perl-MIME-Base64:
                  ----------
                  new:
                      3.15-396.el8
                  old:
              perl-Mozilla-CA:
                  ----------
                  new:
                      20160104-7.module_el8.3.0+416+dee7bcef
                  old:
              perl-Net-SSLeay:
                  ----------
                  new:
                      1.88-1.module_el8.4.0+517+be1595ff
                  old:
              perl-PathTools:
                  ----------
                  new:
                      3.74-1.el8
                  old:
              perl-Pod-Escapes:
                  ----------
                  new:
                      1:1.07-395.el8
                  old:
              perl-Pod-Perldoc:
                  ----------
                  new:
                      3.28-396.el8
                  old:
              perl-Pod-Simple:
                  ----------
                  new:
                      1:3.35-395.el8
                  old:
              perl-Pod-Usage:
                  ----------
                  new:
                      4:1.69-395.el8
                  old:
              perl-Scalar-List-Utils:
                  ----------
                  new:
                      3:1.49-2.el8
                  old:
              perl-Socket:
                  ----------
                  new:
                      4:2.027-3.el8
                  old:
              perl-Storable:
                  ----------
                  new:
                      1:3.11-3.el8
                  old:
              perl-Term-ANSIColor:
                  ----------
                  new:
                      4.06-396.el8
                  old:
              perl-Term-Cap:
                  ----------
                  new:
                      1.17-395.el8
                  old:
              perl-Text-ParseWords:
                  ----------
                  new:
                      3.30-395.el8
                  old:
              perl-Text-Tabs+Wrap:
                  ----------
                  new:
                      2013.0523-395.el8
                  old:
              perl-Time-Local:
                  ----------
                  new:
                      1:1.280-1.el8
                  old:
              perl-URI:
                  ----------
                  new:
                      1.73-3.el8
          ...
         

state.highstate

执行高级状态

[root@master nginx]# salt '*' state.highstate web.nginx.install
minion:
----------
          ID: nginx-install
    Function: pkg.installed
        Name: nginx
      Result: True
     Comment: All specified packages are already installed
     Started: 22:15:23.665768
    Duration: 599.167 ms
     Changes:   
----------
          ID: nginx-service
    Function: service.running
        Name: nginx
      Result: True
     Comment: The service nginx is already running
     Started: 22:15:24.266728
    Duration: 39.898 ms
     Changes:   

Summary for minion
------------
Succeeded: 2
Failed:    0
------------
Total states run:     2
Total run time: 639.065 ms

state.show_state_usage

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

[root@master nginx]# salt '*' state.show_state_usage
minion:
    The minion function caused an exception: Traceback (most recent call last):
      File "/usr/lib/python3.6/site-packages/salt/minion.py", line 1905, in _thread_return
        function_name, function_args, executors, opts, data
      File "/usr/lib/python3.6/site-packages/salt/minion.py", line 1861, in _execute_job_function
        return_data = self.executors[fname](opts, data, func, args, kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader.py", line 1241, in __call__
        return self.loader.run(run_func, *args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader.py", line 2274, in run
        return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
      File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
        return callable(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader.py", line 2289, in _run_as
        return _func_or_method(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/executors/direct_call.py", line 12, in execute
        return func(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader.py", line 1241, in __call__
        return self.loader.run(run_func, *args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader.py", line 2274, in run
        return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
      File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
        return callable(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader.py", line 2289, in _run_as
        return _func_or_method(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/modules/state.py", line 1649, in show_state_usage
        ret = st_.compile_state_usage()
      File "/usr/lib/python3.6/site-packages/salt/state.py", line 4586, in compile_state_usage
        for saltenv, states in self.avail.items():
      File "/usr/lib/python3.6/site-packages/salt/state.py", line 3448, in items
        for saltenv, states in self._avail:
    ValueError: too many values to unpack (expected 2)
ERROR: Minions returned with non-zero exit code

state.show_top

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

[root@master nginx]# salt '*' state.show_top
minion:
    ----------
    base:
        - web.nginx.install

state.top

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

[root@master base]# salt '*' state.top top.sls
minion:
----------
          ID: nginx-install
    Function: pkg.installed
        Name: nginx
      Result: True
     Comment: All specified packages are already installed
     Started: 22:18:21.944293
    Duration: 605.45 ms
     Changes:   
----------
          ID: nginx-service
    Function: service.running
        Name: nginx
      Result: True
     Comment: The service nginx is already running
     Started: 22:18:22.551414
    Duration: 39.368 ms
     Changes:   

Summary for minion
------------
Succeeded: 2
Failed:    0
------------
Total states run:     2
Total run time: 644.818 ms

state.show_sls

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

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

SaltStack常用模块之salt-cp

salt-cp能够很方便的把 master 上的文件批量传到 minion上

//拷贝单个文件到目标主机的/usr/src目录下
[root@master ~]# salt-cp '*' /root/123 /usr/src/
minion:
    ----------
    /usr/src/123:
        True
[root@minion ~]# cd /usr/src/
[root@minion src]# ls
123  debug  kernels
[root@minion src]# cat 123 
asdasdassavasv


设置远程文件权限

[root@master base]# salt minion file.set_mode /usr/src/123 755
minion:
    0755

添加用户

[root@master ~]# salt '*' user.add haha
minion:
    True
#创建用户时指定shell
[root@master ~]# salt '*' user.add test shell=/sbin/nologin 
minion1:
    True
#创建用户指定不创建家目录
[root@master ~]# salt '*' user.add test1 createhome=False
minion1:
    True
[root@minion1 ~]# ls /home/
haha  test
#创建用户时指定附加组
[root@master ~]# salt '*' user.add test2 groups=nginx
minion1:
    True


删除用户

[root@master ~]# salt '*' user.delete haha remove=True
minion:
    True
[root@master ~]# salt '*' cmd.run 'id haha'
minion:
    id: 'haha': no such user
ERROR: Minions returned with non-zero exit code

显示用户密码信息

[root@master user]# salt 'minion' shadow.info root
minion:
    ----------
    expire:
        -1
    inact:
        -1
    lstchg:
        -1
    max:
        99999
    min:
        0
    name:
        root
    passwd:
        $6$lW90D5xvLyWpxLd3$9Fe4R.KNrQ6g6xI4hPoCLcbb2D2haQhRs4TyzHdPWGyIdRiX5HQ046r.1zaosh/lETzbnq3fkjGLfzwoEXisv.
    warn:
        7

查看用户信息

[root@master user]# salt 'minion' user.list_users
minion:
    - adm
    - bin
    - daemon
    - dbus
    - ftp
    - games
    - halt
    - lp
    - mail
    - nginx
    - nobody
    - operator
    - polkitd
    - root
    - shutdown
    - sshd
    - sssd
    - sync
    - systemd-coredump
    - systemd-resolve
    - tss
    - unbound

显示指定用户信息

[root@master user]# salt 'minion' user.info root
minion:
    ----------
    fullname:
        root
    gid:
        0
    groups:
        - root
    home:
        /root
    homephone:
    name:
        root
    other:
    passwd:
        x
    roomnumber:
    shell:
        /bin/bash
    uid:
        0
    workphone:

显示用户密码信息

[root@master user]# salt 'minion' shadow.info root
minion:
    ----------
    expire:
        -1
    inact:
        -1
    lstchg:
        -1
    max:
        99999
    min:
        0
    name:
        root
    passwd:
        $6$lW90D5xvLyWpxLd3$9Fe4R.KNrQ6g6xI4hPoCLcbb2D2haQhRs4TyzHdPWGyIdRiX5HQ046r.1zaosh/lETzbnq3fkjGLfzwoEXisv.
    warn:
        7

SaltStack常用模块之cron

Saltstack module cron

[root@master ~]# salt '*' cron.write_cron_file root /tmp/new_cron
minion:
    True

cron.raw_cron

查看指定用户的计划任务

[root@master ~]# salt '*' cron.raw_cron root
minion:

cron.rm

删除指定用户的 cron 环境变量。

[root@master ~]# salt '*' cron.rm_job root /usr/local/weeklyminion:
    absent
[root@master ~]# salt '*' cron.rm_job root /usr/bin/foo dayweek=1
minion:
    absent

cron.list_tab

返回指定用户的crontab内容

[root@master ~]# salt '*' cron.list_tab root
minion:
    ----------
    crons:
    env:
    pre:
    special:

cron.write_cron_file_verbose

将文件内容写入用户的 crontab 并在出错时返回错误消息

[root@master ~]# salt '*' cron.write_cron_file_verbose root /tmp/new_cron
minion:
    ----------
    pid:
        17017
    retcode:
        0
    stderr:
    stdout:

cron.rm_env

删除指定用户的 cron 环境变量。

[root@master ~]# salt '*' cron.rm_env root MAILTO
minion:
    absent

cron.set_job

为指定用户设置 cron 作业。

[root@master ~]# salt '*' cron.set_job root '*' '*' '*' '*' 1 /usr/local/weekly
minion:
    new

cron.set_env

在 crontab 中设置环境变量。

[root@master ~]# salt '*' cron.set_env root MAILTO user@example.com
minion:
    new

cron.rm_special

删除指定用户的特殊 cron 作业

[root@master ~]# salt '*' cron.rm_special root /usr/bin/foo
minion:
    absent

cron.set_special

在 crontab 中设置一个特殊的命令

[root@master ~]# salt '*' cron.set_special root @hourly 'echo foobar'
minion:
    new

cron.rm_job

删除指定用户的 cron 作业。如果指定了任何日期/时间参数,则仅当指定的参数匹配时才会删除作业。

[root@master ~]# salt '*' cron.rm_job root /usr/local/weeklyminion:
    removed
[root@master ~]# salt '*' cron.rm_job root /usr/bin/foo dayweek=1
minion:
    absent

cron.ls

该函数是 的别名list_tab

返回指定用户的crontab内容

[root@master ~]# salt '*' cron.list_tab root
minion:
    ----------
    crons:
    env:
        |_
          ----------
          name:
              MAILTO
          value:
              user@example.com
    pre:
    special:
        |_
          ----------
          cmd:
              echo foobar
          comment:
              None
          commented:
              False
          identifier:
              None
          spec:
              @hourly

以上是关于SaltStack常用的模块的主要内容,如果未能解决你的问题,请参考以下文章

saltstack详解+部署apache服务

saltstack 常用模块

saltstack state.sls常用功能模板编写

ansible安装部署和配置常用模块整理

Saltstack 常用的模块及API

saltstack使用指南----常用执行模块