salt 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

salt 命令安装:


-bash/zsh: salt command not not found

# Windows (WSL2)
sudo apt-get update sudo apt-get install salt-master

# Debian
apt-get install salt-master

# Ubuntu
apt-get install salt-master

# Alpine
apk add salt

# Arch Linux
pacman -S salt

# Fedora
dnf install salt-master

# OS X
brew install salt

# Raspbian
apt-get install salt-master

# Docker
docker run cmd.cat/salt salt

salt 命令补充说明:


Salt 是世界上速度最快、最智能、可扩展性最好的自动化引擎。Salt 通过 Broadcom 的 Tanzu Salt(以前称为 Aria Automation Config / vRealize Automation SaltStack Config / SaltStack Enterprise)为 VMware 提供支持,并且可以在 Juniper、Cisco、Cloudflare、Nutanix、SUSE 和 Tieto 等公司的产品中找到。

Salt 基于 Python 构建,是一款事件驱动的自动化工具和框架,用于部署、配置和管理复杂的 IT 系统。使用 Salt 可以自动执行常见的基础架构管理任务,并确保基础架构的所有组件都以一致的预期状态运行。

Salt 有很多用途,包括配置管理,它涉及:

  • 管理操作系统部署和配置。
  • 安装和配置软件应用程序和服务。
  • 管理服务器、虚拟机、容器、数据库、Web 服务器、网络设备等。
  • 确保配置一致并防止配置偏差。

Salt 是配置管理的理想选择,因为它可插拔、可定制,并且能够与许多现有技术完美兼容。Salt 使您能够部署和管理使用几乎任何操作系统上运行的任何技术栈的应用程序,包括来自不同供应商的不同类型的网络设备,例如交换机和路由器。

除了配置管理之外,Salt 还可以:

  • 自动化和协调日常 IT 流程,例如计划服务器停机或升级操作系统或应用程序所需的常见任务。
  • 创建具有自我感知和自我修复能力的系统,可以自动响应中断、常见管理问题或其他重要事件。

salt 命令语法:


salt '*' [ options ] sys.doc

salt -E '.*' [ options ] sys.doc cmd

salt -G 'os:Arch.*' [ options ] test.ping

salt -C 'G@os:Arch.* and webserv* or G@kernel:FreeBSD' [ options ] test.ping

salt 命令选项:


-h, --help
      Print a usage message briefly summarizing these command-line options
-t TIMEOUT, --timeout=TIMEOUT
      The timeout in seconds to wait for replies from the Salt minions. The timeout number specifes how long the command line client will wait to query the minions and check on running jobs.
-s STATIC, --static=STATIC
      By default as of version 0.9.8 the salt command returns data to the console as it is received from minions, but previous releases would return data only after all data was received. To only return the data with a hard timeout and after all minions have returned then use the static option.
-b BATCH, --batch-size=BATCH
      Instead of executing on all targeted minions at once, execute on a progressive set of minions. This option takes an argument in the form of an explicit number of minions to execute at once, or a percentage of minions to execute on.
-a EAUTH, --auth=EAUTH
      Pass in an external authentication medium to validate against. The credentials will be prompted for. Can be used with the -T option.
-T, --make-token
      Used in conjunction with the -a option. This creates a token that allows for the authenticated user to send commands without needing to re-authenticate.
--version
      Print the version of Salt that is running.
--versions-report
      Show program's dependencies version number and exit
-E, --pcre
      The target expression will be interpreted as a pcre regular expression rather than a shell glob.
-L, --list
      The target expression will be interpreted as a comma delimited list, example: server1.foo.bar,server2.foo.bar,example7.quo.qux
-G, --grain
      The target expression matches values returned by the Salt grains system on the minions. The target expression is in the format of ':'; example: 'os:Arch*'
      This was changed in version 0.9.8 to accept glob expressions instead of regular expression. To use regular expression matching with grains use the --grain-pcre option.

--grain-pcre
      The target expression matches values returned by the Salt grains system on the minions. The target expression is in the format of ':< regular expression>'; example: 'os:Arch.*'
-C, --compound
      Utilize many target definitions to make the call very granular. This option takes a group of targets separated by and or or. The default matcher is a glob as usual, if something other than a glob is used preface it with the letter denoting the type, example: 'webserv* and G@os:Debian or E@db*' make sure that the compound target is encapsulated in quotes.
-X, --exsel
      Instead of using shell globs use the return code of a function.
-N, --nodegroup
      Use a predefined compound target defined in the Salt master configuration file.
-I, --pillar
      Instead of using shell globs to evaluate the target use a pillar value to identify targets, the syntax for the target is the pillar key followed by a glob expression: "role:production*"
-S, --ipcidr
      Match based on Subnet (CIDR notation) or IPv4 address.
-R, --range
      Instead of using shell globs to evaluate the target use a range expression to identify targets. Range expressions look like %cluster.
Using the Range option requires that a range server is set up and the location of the range server is referenced in the master configuration file.

--return
      Chose an alternative returner to call on the minion, if an alternative returner is used then the return will not come back to the command line but will be sent to the specified return system.
-c CONFIG_DIR, --config-dir=CONFIG_dir
      The location of the Salt configuration directory, this directory contains the configuration files for Salt master and minions. The default location on most systems is /etc/salt.
-v VERBOSE, --verbose
      Turn on verbosity for the salt call, this will cause the salt command to print out extra data like the job id.
-d, --doc, --documentation
      Return the documentation for the module functions available on the minions
--out
      Pass in an alternative outputter to display the return of data. This outputter can be any of the available outputters: grains, highstate, json, key, overstatestage, pprint, raw, txt, yaml Some outputters are formatted only for data returned from specific functions, for instance the grains outputter will not work for non grains data. If an outputter is used that does not support the data passed into it, then Salt will fall back on the pprint outputter and display the return data using the python pprint library.

--out-indent OUTPUT_INDENT, --output-indent OUTPUT_INDENT
      Print the output indented by the provided value in spaces. Negative values disables indentation. Only applicable in outputters that support indentation.
--no-color
      Disable all colored output

salt 命令实例:


salt 列出已连接的 Minion:

salt '*' test.ping

salt 对所有连接的 minions 执行 highstate:

salt '*' state.highstate

salt 使用操作系统包管理器(apt、yum、brew)在部分 minions 上升级包:

salt '*.example.com' pkg.upgrade

salt 在特定的 minion 上执行任意命令:

salt 'minion_id' cmd.run "ls "

salt 命令扩展阅读:


 

CommandNotFound ⚡️ 坑否 - 其他频道扩展阅读:




salt 命令评论