1
0

index.rst 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. Where the args are:
  47. ``opts``:
  48. Dictionary containing the minion configuration options
  49. ``data``:
  50. Dictionary containing the load data including ``executor_opts`` passed via
  51. cmdline/API.
  52. ``func``, ``args``, ``kwargs``:
  53. Execution module function to be executed and its arguments. For instance the
  54. simplest ``direct_call`` executor just runs it as ``func(*args, **kwargs)``.
  55. ``Returns``:
  56. ``None`` if the execution sequence must be continued with the next executor.
  57. Error string or execution result if the job is done and execution must be
  58. stopped.
  59. Specific options could be passed to the executor via minion config or via
  60. ``executor_opts`` argument. For instance to access ``splaytime`` option set by
  61. minion config executor should access ``opts.get('splaytime')``. To access the
  62. option set by commandline or API ``data.get('executor_opts',
  63. {}).get('splaytime')`` should be used. So if an option is safe and must be
  64. accessible by user executor should check it in both places, but if an option is
  65. unsafe it should be read from the only config ignoring the passed request data.
  66. There is also a function named ``all_missing_func`` which the name of the
  67. ``func`` is passed, which can be used to verify if the command should still be
  68. run, even if it is not loaded in minion_mods.