Saltstack 简明教程

SaltStack - Orchestration

总体而言, orchestration 是对系统进行自动化协调和安排。Orchestrate Runner用于在SaltStack中执行编排。

In general, orchestration is an automated coordination and arrangement of systems. Orchestrate runner is used to perform the orchestration in SaltStack.

Orchestrate Runner

Orchestrate Runner提供了 OverState (以前的系统)的所有功能。它最初被称为 state.sls Runner。该Orchestrate Runner用于将Salt状态系统概括为Salt master上下文。

he Orchestrate Runner offers all the functionality of the OverState (previous system). It is originally called as the state.sls runner. This orchestrate runner is used to generalize the Salt state system to a Salt master context.

state.slsstate.highstate 功能在每个Salt minion上执行,但 state.orchestrate runner在master上执行。 state.orchestrate Runner允许您将整个基础架构完全作为状态进行管理。让我们了解如何完成一个简单的执行过程。

The state.sls and the state.highstate functions are executed on each Salt minion, but the state.orchestrate runner is executed on the master. The state.orchestrate runner allows you to manage your entire infrastructure as state fully. Let us understand how to go through a simple execution process.

Simple Execution

编排运行器命令与 state.sls 函数相同,但是可以使用“salt-run”而不是salt来执行该命令。

The Orchestrate Runner command is same as the state.sls function, but you can execute it with the “salt-run” instead of salt.

假设您在 /srv/salt/orch/samples.sls 处有一个 sample.sls 文件。将以下代码添加到该文件中。

Assume that you have a sample.sls file located at /srv/salt/orch/samples.sls. Add the following code in that file.

sample.sls

sample.sls

install_nginx:
   salt.state:
      - tgt: 'web*'
      - sls:
         - nginx

以下命令用于在主控程序上运行,它将应用该文件中定义的状态。

The following command is used to run on the master and it will apply the states defined in that file.

salt-run state.orchestrate orch.sample

它将生成以下 output

It will produce the following output

saltmaster.local_master:
----------
   ID: install_nginx
   Function: salt.state
   Result: True
   Comment: States ran successfully.
   Started: 11:54:56.308078
   Duration: 63.401 ms
   Changes:

Summary for saltmaster.local_master
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
Total run time:  63.401 ms
root@saltmaster:/home/vagrant#

这里,根据当前版本,运行程序函数更名为 state.orchestrate 。这将有助于避免与 state.sls 执行函数混淆,但必须使用 state.sls 的先前版本。

Here, according to the Current Version, the runner function was renamed to state.orchestrate. This will be helpful to avoid confusion with the state.sls execution function, but the previous versions of state.sls must be used.

Execute Function

要执行函数,您应使用 salt.function 。考虑一个位于 /srv/salt/orch/data.sls 的文件 data.sls 。现在,在该文件中添加以下更改。

To execute a function, you should use the salt.function. Consider a file data.sls located at /srv/salt/orch/data.sls. Now, add the following changes in that file.

data.sls

data.sls

cmd.run:
   salt.function:
      - tgt: '*'
      - arg:
         - rm -rf /tmp/data

以下命令用于执行 Salt 函数。

The following command is used to execute the Salt function.

root@saltmaster:/home/vagrant# salt-run state.orchestrate orch.data

它将生成以下 output

It will produce the following output

saltmaster.local_master:
----------
   ID: cmd.run
   Function: salt.function
   Result: True
   Comment: Function ran successfully. Function cmd.run ran on minion1, minion2.
   Started: 12:14:54.791635
   Duration: 234.615 ms
   Changes:
      minion1:

      minion2:
Summary for saltmaster.local_master
------------
Succeeded: 1 (changed = 1)
Failed:    0
------------
Total states run:     1
Total run time: 234.615 ms