1
0

index.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. .. _executors:
  2. =========
  3. Executors
  4. =========
  5. Executors are used by minion to execute module functions. Executors can be used
  6. to modify the functions behavior, do any pre-execution steps or execute in a
  7. specific way like sudo executor.
  8. Executors could be passed as a list and they will be used one-by-one in the
  9. order. If an executor returns ``None`` the next one will be called. If an
  10. executor returns non-``None`` the execution sequence is terminated and the
  11. returned value is used as a result. It's a way executor could control modules
  12. execution working as a filter. Note that executor could actually not execute
  13. the function but just do something else and return ``None`` like ``splay``
  14. executor does. In this case some other executor have to be used as a final
  15. executor that will actually execute the function. See examples below.
  16. Executors list could be passed by minion config file in the following way:
  17. .. code-block:: yaml
  18. module_executors:
  19. - splay
  20. - direct_call
  21. splaytime: 30
  22. The same could be done by command line:
  23. .. code-block:: bash
  24. salt -t 40 --module-executors='[splay, direct_call]' --executor-opts='{splaytime: 30}' '*' test.version
  25. And the same command called via netapi will look like this:
  26. .. code-block:: bash
  27. curl -sSk https://localhost:8000 \
  28. -H 'Accept: application/x-yaml' \
  29. -H 'X-Auth-Token: 697adbdc8fe971d09ae4c2a3add7248859c87079' \
  30. -H 'Content-type: application/json' \
  31. -d '[{
  32. "client": "local",
  33. "tgt": "*",
  34. "fun": "test.version",
  35. "module_executors": ["splay", "direct_call"],
  36. "executor_opts": {"splaytime": 10}
  37. }]'
  38. .. seealso:: :ref:`The full list of executors <all-salt.executors>`
  39. Writing Salt Executors
  40. ----------------------
  41. A Salt executor is written in a similar manner to a Salt execution module.
  42. Executor is a python module placed into the ``executors`` folder and containing
  43. the ``execute`` function with the following signature:
  44. .. code-block:: python
  45. def execute(opts, data, func, args, kwargs):
  46. ...
  47. Where the args are:
  48. ``opts``:
  49. Dictionary containing the minion configuration options
  50. ``data``:
  51. Dictionary containing the load data including ``executor_opts`` passed via
  52. cmdline/API.
  53. ``func``, ``args``, ``kwargs``:
  54. Execution module function to be executed and its arguments. For instance the
  55. simplest ``direct_call`` executor just runs it as ``func(*args, **kwargs)``.
  56. ``Returns``:
  57. ``None`` if the execution sequence must be continued with the next executor.
  58. Error string or execution result if the job is done and execution must be
  59. stopped.
  60. Specific options could be passed to the executor via minion config or via
  61. ``executor_opts`` argument. For instance to access ``splaytime`` option set by
  62. minion config executor should access ``opts.get('splaytime')``. To access the
  63. option set by commandline or API ``data.get('executor_opts',
  64. {}).get('splaytime')`` should be used. So if an option is safe and must be
  65. accessible by user executor should check it in both places, but if an option is
  66. unsafe it should be read from the only config ignoring the passed request data.
  67. There is also a function named ``all_missing_func`` which the name of the
  68. ``func`` is passed, which can be used to verify if the command should still be
  69. run, even if it is not loaded in minion_mods.