2016-02-01 03:10:02 +00:00
|
|
|
.. _orchestrate-runner:
|
|
|
|
|
|
|
|
==================
|
|
|
|
Orchestrate Runner
|
|
|
|
==================
|
|
|
|
|
2017-02-16 07:52:05 +00:00
|
|
|
Executing states or highstate on a minion is perfect when you want to ensure that
|
|
|
|
minion configured and running the way you want. Sometimes however you want to
|
|
|
|
configure a set of minions all at once.
|
|
|
|
|
|
|
|
For example, if you want to set up a load balancer in front of a cluster of web
|
|
|
|
servers you can ensure the load balancer is set up first, and then the same
|
|
|
|
matching configuration is applied consistently across the whole cluster.
|
|
|
|
|
|
|
|
Orchestration is the way to do this.
|
|
|
|
|
2016-02-01 03:10:02 +00:00
|
|
|
|
|
|
|
The Orchestrate Runner
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
.. versionadded:: 0.17.0
|
|
|
|
|
|
|
|
.. note:: Orchestrate Deprecates OverState
|
|
|
|
|
|
|
|
The Orchestrate Runner (originally called the state.sls runner) offers all
|
|
|
|
the functionality of the OverState, but with some advantages:
|
|
|
|
|
2016-12-15 23:09:27 +00:00
|
|
|
* All :ref:`requisites` available in states can be
|
2016-02-01 03:10:02 +00:00
|
|
|
used.
|
|
|
|
* The states/functions will also work on salt-ssh minions.
|
|
|
|
|
2016-09-28 18:45:59 +00:00
|
|
|
The Orchestrate Runner replaced the OverState system in Salt 2015.8.0.
|
2016-02-01 03:10:02 +00:00
|
|
|
|
|
|
|
The orchestrate runner generalizes the Salt state system to a Salt master
|
2016-09-28 18:45:59 +00:00
|
|
|
context. Whereas the ``state.sls``, ``state.highstate``, et al. functions are
|
2016-02-01 03:10:02 +00:00
|
|
|
concurrently and independently executed on each Salt minion, the
|
|
|
|
``state.orchestrate`` runner is executed on the master, giving it a
|
|
|
|
master-level view and control over requisites, such as state ordering and
|
|
|
|
conditionals. This allows for inter minion requisites, like ordering the
|
|
|
|
application of states on different minions that must not happen simultaneously,
|
|
|
|
or for halting the state run on all minions if a minion fails one of its
|
|
|
|
states.
|
|
|
|
|
2016-09-28 18:45:59 +00:00
|
|
|
The ``state.sls``, ``state.highstate``, et al. functions allow you to statefully
|
2016-02-01 03:10:02 +00:00
|
|
|
manage each minion and the ``state.orchestrate`` runner allows you to
|
|
|
|
statefully manage your entire infrastructure.
|
|
|
|
|
2016-09-28 19:08:09 +00:00
|
|
|
Writing SLS Files
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Orchestrate SLS files are stored in the same location as State SLS files. This
|
|
|
|
means that both ``file_roots`` and ``gitfs_remotes`` impact what SLS files are
|
|
|
|
available to the reactor and orchestrator.
|
|
|
|
|
2016-09-29 03:07:40 +00:00
|
|
|
It is recommended to keep reactor and orchestrator SLS files in their own
|
|
|
|
uniquely named subdirectories such as ``_orch/``, ``orch/``, ``_orchestrate/``,
|
|
|
|
``react/``, ``_reactor/``, etc. This will avoid duplicate naming and will help
|
|
|
|
prevent confusion.
|
2016-09-28 19:08:09 +00:00
|
|
|
|
2016-02-01 03:10:02 +00:00
|
|
|
Executing the Orchestrate Runner
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
The Orchestrate Runner command format is the same as for the ``state.sls``
|
|
|
|
function, except that since it is a runner, it is executed with ``salt-run``
|
|
|
|
rather than ``salt``. Assuming you have a state.sls file called
|
2016-09-28 18:45:59 +00:00
|
|
|
``/srv/salt/orch/webserver.sls`` the following command, run on the master,
|
|
|
|
will apply the states defined in that file.
|
2016-02-01 03:10:02 +00:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
salt-run state.orchestrate orch.webserver
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
``state.orch`` is a synonym for ``state.orchestrate``
|
|
|
|
|
|
|
|
.. versionchanged:: 2014.1.1
|
|
|
|
|
|
|
|
The runner function was renamed to ``state.orchestrate`` to avoid confusion
|
|
|
|
with the :mod:`state.sls <salt.modules.state.sls>` execution function. In
|
|
|
|
versions 0.17.0 through 2014.1.0, ``state.sls`` must be used.
|
|
|
|
|
2016-06-11 14:47:27 +00:00
|
|
|
Masterless Orchestration
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2016-10-27 21:26:30 +00:00
|
|
|
.. versionadded:: 2016.11.0
|
2016-06-11 14:47:27 +00:00
|
|
|
|
|
|
|
To support salt orchestration on masterless minions, the Orchestrate Runner is
|
|
|
|
available as an execution module. The syntax for masterless orchestration is
|
|
|
|
exactly the same, but it uses the ``salt-call`` command and the minion
|
|
|
|
configuration must contain the ``file_mode: local`` option. Alternatively,
|
|
|
|
use ``salt-call --local`` on the command line.
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
salt-call --local state.orchestrate orch.webserver
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
Masterless orchestration supports only the ``salt.state`` command in an
|
|
|
|
sls file; it does not (currently) support the ``salt.function`` command.
|
|
|
|
|
2016-02-01 03:10:02 +00:00
|
|
|
Examples
|
|
|
|
~~~~~~~~
|
|
|
|
|
|
|
|
Function
|
|
|
|
^^^^^^^^
|
|
|
|
|
|
|
|
To execute a function, use :mod:`salt.function <salt.states.saltmod.function>`:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
# /srv/salt/orch/cleanfoo.sls
|
|
|
|
cmd.run:
|
|
|
|
salt.function:
|
|
|
|
- tgt: '*'
|
|
|
|
- arg:
|
|
|
|
- rm -rf /tmp/foo
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
salt-run state.orchestrate orch.cleanfoo
|
|
|
|
|
2016-04-20 17:23:40 +00:00
|
|
|
If you omit the "name" argument, the ID of the state will be the default name,
|
|
|
|
or in the case of ``salt.function``, the execution module function to run. You
|
|
|
|
can specify the "name" argument to avoid conflicting IDs:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
copy_some_file:
|
|
|
|
salt.function:
|
|
|
|
- name: file.copy
|
|
|
|
- tgt: '*'
|
|
|
|
- arg:
|
|
|
|
- /path/to/file
|
|
|
|
- /tmp/copy_of_file
|
|
|
|
- kwarg:
|
2016-11-21 20:23:08 +00:00
|
|
|
remove_existing: true
|
2016-04-20 17:23:40 +00:00
|
|
|
|
2016-02-01 03:10:02 +00:00
|
|
|
State
|
|
|
|
^^^^^
|
|
|
|
|
|
|
|
To execute a state, use :mod:`salt.state <salt.states.saltmod.state>`.
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
# /srv/salt/orch/webserver.sls
|
|
|
|
install_nginx:
|
|
|
|
salt.state:
|
|
|
|
- tgt: 'web*'
|
|
|
|
- sls:
|
|
|
|
- nginx
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
salt-run state.orchestrate orch.webserver
|
|
|
|
|
|
|
|
Highstate
|
|
|
|
^^^^^^^^^
|
|
|
|
|
|
|
|
To run a highstate, set ``highstate: True`` in your state config:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
# /srv/salt/orch/web_setup.sls
|
|
|
|
webserver_setup:
|
|
|
|
salt.state:
|
|
|
|
- tgt: 'web*'
|
|
|
|
- highstate: True
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
salt-run state.orchestrate orch.web_setup
|
|
|
|
|
2017-01-04 18:34:55 +00:00
|
|
|
Runner
|
|
|
|
^^^^^^
|
|
|
|
|
|
|
|
To execute another runner, use :mod:`salt.runner <salt.states.saltmod.runner>`.
|
|
|
|
For example to use the ``cloud.profile`` runner in your orchestration state
|
|
|
|
additional options to replace values in the configured profile, use this:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
# /srv/salt/orch/deploy.sls
|
|
|
|
create_instance:
|
|
|
|
salt.runner:
|
|
|
|
- name: cloud.profile
|
|
|
|
- prof: cloud-centos
|
|
|
|
- provider: cloud
|
|
|
|
- instances:
|
|
|
|
- server1
|
|
|
|
- opts:
|
|
|
|
minion:
|
|
|
|
master: master1
|
|
|
|
|
|
|
|
To get a more dynamic state, use jinja variables together with
|
|
|
|
``inline pillar data``.
|
|
|
|
Using the same example but passing on pillar data, the state would be like
|
|
|
|
this.
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
# /srv/salt/orch/deploy.sls
|
|
|
|
{% set servers = salt['pillar.get']('servers', 'test') %}
|
2017-11-07 16:36:10 +00:00
|
|
|
{% set master = salt['pillar.get']('master', 'salt') %}
|
2017-01-04 18:34:55 +00:00
|
|
|
create_instance:
|
|
|
|
salt.runner:
|
|
|
|
- name: cloud.profile
|
|
|
|
- prof: cloud-centos
|
|
|
|
- provider: cloud
|
|
|
|
- instances:
|
|
|
|
- {{ servers }}
|
|
|
|
- opts:
|
|
|
|
minion:
|
|
|
|
master: {{ master }}
|
|
|
|
|
|
|
|
To execute with pillar data.
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
salt-run state.orch orch.deploy pillar='{"servers": "newsystem1",
|
|
|
|
"master": "mymaster"}'
|
|
|
|
|
2016-02-01 03:10:02 +00:00
|
|
|
|
|
|
|
More Complex Orchestration
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Many states/functions can be configured in a single file, which when combined
|
2016-12-15 23:09:27 +00:00
|
|
|
with the full suite of :ref:`requisites`, can be used
|
2016-02-01 03:10:02 +00:00
|
|
|
to easily configure complex orchestration tasks. Additionally, the
|
|
|
|
states/functions will be executed in the order in which they are defined,
|
2016-12-15 23:09:27 +00:00
|
|
|
unless prevented from doing so by any :ref:`requisites`, as is the default in
|
|
|
|
SLS files since 0.17.0.
|
2016-02-01 03:10:02 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
2016-04-20 17:23:40 +00:00
|
|
|
bootstrap_servers:
|
2016-02-01 03:10:02 +00:00
|
|
|
salt.function:
|
2016-04-20 17:23:40 +00:00
|
|
|
- name: cmd.run
|
2016-02-01 03:10:02 +00:00
|
|
|
- tgt: 10.0.0.0/24
|
|
|
|
- tgt_type: ipcidr
|
|
|
|
- arg:
|
|
|
|
- bootstrap
|
|
|
|
|
|
|
|
storage_setup:
|
|
|
|
salt.state:
|
|
|
|
- tgt: 'role:storage'
|
|
|
|
- tgt_type: grain
|
|
|
|
- sls: ceph
|
|
|
|
- require:
|
|
|
|
- salt: webserver_setup
|
|
|
|
|
|
|
|
webserver_setup:
|
|
|
|
salt.state:
|
|
|
|
- tgt: 'web*'
|
|
|
|
- highstate: True
|
|
|
|
|
|
|
|
Given the above setup, the orchestration will be carried out as follows:
|
|
|
|
|
|
|
|
1. The shell command ``bootstrap`` will be executed on all minions in the
|
|
|
|
10.0.0.0/24 subnet.
|
|
|
|
|
|
|
|
2. A Highstate will be run on all minions whose ID starts with "web", since
|
|
|
|
the ``storage_setup`` state requires it.
|
|
|
|
|
|
|
|
3. Finally, the ``ceph`` SLS target will be executed on all minions which have
|
|
|
|
a grain called ``role`` with a value of ``storage``.
|
|
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
Remember, salt-run is always executed on the master.
|