index.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. .. _modular-systems:
  2. ===============
  3. Modular Systems
  4. ===============
  5. When first working with Salt, it is not always clear where all of the modular
  6. components are and what they do. Salt comes loaded with more modular systems
  7. than many users are aware of, making Salt very easy to extend in many places.
  8. The most commonly used modular systems are execution modules and states. But
  9. the modular systems extend well beyond the more easily exposed components
  10. and are often added to Salt to make the complete system more flexible.
  11. .. toctree::
  12. :maxdepth: 2
  13. :glob:
  14. developing
  15. configuration
  16. Loading Modules
  17. ===============
  18. Modules come primarily from several sources:
  19. * The Salt package itself
  20. * The Salt File Server
  21. * The extmods directory
  22. * Secondary packages installed
  23. Using one source to override another is not supported.
  24. The Salt Package
  25. ----------------
  26. Salt itself ships with a large number of modules. These are part of the Salt
  27. package itself and don't require the user to do anything to use them. (Although
  28. a number of them have additional dependencies and/or configuration.)
  29. The Salt File Server
  30. --------------------
  31. The user may add modules by simply placing them in special directories in their
  32. :ref:`fileserver <file-server>`.
  33. The name of the directory inside of the file server is the directory name
  34. prepended by underscore, such as:
  35. - :file:`_grains`
  36. - :file:`_modules`
  37. - :file:`_states`
  38. Modules must be synced before they can be used. This can happen a few ways,
  39. discussed below.
  40. .. note::
  41. Using saltenvs besides ``base`` may not work in all contexts.
  42. Sync Via States
  43. ~~~~~~~~~~~~~~~
  44. The minion configuration contains an option ``autoload_dynamic_modules``
  45. which defaults to ``True``. This option makes the state system refresh all
  46. dynamic modules when states are run. To disable this behavior set
  47. :conf_minion:`autoload_dynamic_modules` to ``False`` in the minion config.
  48. When dynamic modules are autoloaded via states, only the modules defined in the
  49. same saltenvs as the states currently being run.
  50. Also it is possible to use the explicit ``saltutil.sync_*`` :py:mod:`state functions <salt.states.saltutil>`
  51. to sync the modules (previously it was necessary to use the ``module.run`` state):
  52. .. code-block::yaml
  53. synchronize_modules:
  54. saltutil.sync_modules:
  55. - refresh: True
  56. Sync Via the saltutil Module
  57. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  58. The saltutil module has a number of functions that can be used to sync all
  59. or specific dynamic modules. The ``saltutil.sync_*``
  60. :py:mod:`execution functions <salt.modules.saltutil>` and
  61. :py:mod:`runner functions <salt.runners.saltutil>` can be used to sync modules
  62. to minions and the master, respectively.
  63. The extmods Directory
  64. ---------------------
  65. Any files places in the directory set by ``extension_modules`` settings
  66. (:conf_minion:`minion <extension_modules>`,
  67. :conf_master:`master <extension_modules>`, default
  68. ``/var/cache/salt/*/extmods``) can also be loaded as modules. Note that these
  69. directories are also used by the ``saltutil.sync_*`` functions (mentioned
  70. above) and files may be overwritten.
  71. Secondary Packages
  72. ------------------
  73. Third-party packages may also add modules to Salt if they are installed in the
  74. same system and Python environment as the Salt Minion or Master.
  75. This is done via setuptools entry points:
  76. .. code-block:: python
  77. setup(
  78. # ...
  79. entry_points={
  80. 'salt.loader': [
  81. 'module_dirs=spirofs.loader:module',
  82. ],
  83. },
  84. # ...
  85. )
  86. Note that these are not synced from the Salt Master to the Minions. They must be
  87. installed independently on each Minion.
  88. Module Types
  89. ============
  90. The specific names used by each loading method above are as follows. See sections below
  91. for a short summary of each of these systems.
  92. .. _module-name-table:
  93. ============ ================================================================ ========================= =====================
  94. Module Type Salt Package Name FS/Directory Name Entry Point
  95. ============ ================================================================ ========================= =====================
  96. Auth ``salt.auth`` (:ref:`index <external-logging-handlers>`) ``auth`` [#no-fs]_ ``auth_dirs``
  97. Beacon ``salt.beacons`` (:ref:`index <beacons>`) ``beacons`` ``beacons_dirs``
  98. Cache ``salt.cache`` (:ref:`index <all-salt.cache>`) ``cache`` ``cache_dirs``
  99. Cloud ``salt.cloud.clouds`` (:ref:`index <all-salt.clouds>`) ``clouds`` ``cloud_dirs``
  100. Engine ``salt.engines`` (:ref:`index <engines>`) ``engines`` ``engines_dirs``
  101. Execution ``salt.modules`` (:ref:`index <all-salt.modules>`) ``modules`` ``module_dirs``
  102. Executor ``salt.executors`` (:ref:`index <all-salt.executors>`) ``executors`` ``executor_dirs``
  103. File Server ``salt.fileserver`` (:ref:`index <file-server>`) ``fileserver`` ``fileserver_dirs``
  104. Grain ``salt.grains`` (:ref:`index <all-salt.grains>`) ``grains`` ``grains_dirs``
  105. Log Handler ``salt.log.handlers`` (:ref:`index <external-logging-handlers>`) ``log_handlers`` ``log_handlers_dirs``
  106. Matcher ``salt.matchers`` ``matchers`` ``matchers_dirs``
  107. Metaproxy ``salt.metaproxy`` ``metaproxy`` [#no-fs]_ ``metaproxy_dirs``
  108. Net API ``salt.netapi`` (:ref:`index <all-netapi-modules>`) ``netapi`` [#no-fs]_ ``netapi_dirs``
  109. Outputter ``salt.output`` (:ref:`index <all-salt.output>`) ``output`` ``outputter_dirs``
  110. Pillar ``salt.pillar`` (:ref:`index <all-salt.pillars>`) ``pillar`` ``pillar_dirs``
  111. Proxy ``salt.proxy`` (:ref:`index <all-salt.proxy>`) ``proxy`` ``proxy_dirs``
  112. Queue ``salt.queues`` (:ref:`index <all-salt.queues>`) ``queues`` ``queue_dirs``
  113. Renderer ``salt.renderers`` (:ref:`index <all-salt.renderers>`) ``renderers`` ``render_dirs``
  114. Returner ``salt.returners`` (:ref:`index <all-salt.returners>`) ``returners`` ``returner_dirs``
  115. Roster ``salt.roster`` (:ref:`index <all-salt.roster>`) ``roster`` ``roster_dirs``
  116. Runner ``salt.runners`` (:ref:`index <all-salt.runners>`) ``runners`` ``runner_dirs``
  117. SDB ``salt.sdb`` (:ref:`index <all-salt.sdb>`) ``sdb`` ``sdb_dirs``
  118. Serializer ``salt.serializers`` (:ref:`index <all-salt.serializers>`) ``serializers`` [#no-fs]_ ``serializers_dirs``
  119. SPM pkgdb ``salt.spm.pkgdb`` ``pkgdb`` [#no-fs]_ ``pkgdb_dirs``
  120. SPM pkgfiles ``salt.spm.pkgfiles`` ``pkgfiles`` [#no-fs]_ ``pkgfiles_dirs``
  121. SSH Wrapper ``salt.client.ssh.wrapper`` ``wrapper`` [#no-fs]_ ``wrapper_dirs``
  122. State ``salt.states`` (:ref:`index <all-salt.states>`) ``states`` ``states_dirs``
  123. Thorium ``salt.thorium`` (:ref:`index <all-salt.thorium>`) ``thorium`` ``thorium_dirs``
  124. Tokens ``salt.tokens`` ``tokens`` ``tokens_dirs``
  125. Top ``salt.tops`` (:ref:`index <all-salt.tops>`) ``tops`` ``top_dirs``
  126. Util ``salt.utils`` ``utils`` ``utils_dirs``
  127. Wheel ``salt.wheels`` (:ref:`index <all-salt.wheel>`) ``wheel`` ``wheel_dirs``
  128. ============ ================================================================ ========================= =====================
  129. .. [#no-fs] These modules cannot be loaded from the Salt File Server.
  130. .. note::
  131. While it is possible to import modules directly with the import statement,
  132. it is strongly recommended that the appropriate
  133. :ref:`dunder dictionary <dunder-dictionaries>` is used to access them
  134. instead. This is because a number of factors affect module names, module
  135. selection, and module overloading.
  136. Auth
  137. ----
  138. The auth module system allows for external authentication routines to be easily
  139. added into Salt. The `auth` function needs to be implemented to satisfy the
  140. requirements of an auth module. Use the ``pam`` module as an example.
  141. See :ref:`External Authentication System <acl-eauth>` for more about
  142. authentication in Salt.
  143. Beacon
  144. ------
  145. * :ref:`Writing Beacons <writing-beacons>`
  146. Beacons are polled by the Salt event loop to monitor non-salt processes. See
  147. :ref:`Beacons <beacons>` for more information about the beacon system.
  148. Cache
  149. -----
  150. The minion cache is used by the master to store various information about
  151. minions. See :ref:`Minion Data Cache <cache>` for more information.
  152. Cloud
  153. -----
  154. Cloud modules are backend implementations used by :ref:`Salt Cloud <salt-cloud>`.
  155. Engine
  156. ------
  157. Engines are open-ended services managed by the Salt daemon (both master and
  158. minion). They may interact with event loop, call other modules, or a variety of
  159. non-salt tasks. See :ref:`Salt Engines <engines>` for complete details.
  160. Execution
  161. ---------
  162. .. toctree::
  163. :maxdepth: 1
  164. :glob:
  165. /ref/modules/index
  166. Execution modules make up the core of the functionality used by Salt to
  167. interact with client systems. The execution modules create the core system
  168. management library used by all Salt systems, including states, which
  169. interact with minion systems.
  170. Execution modules are completely open ended in their execution. They can
  171. be used to do anything required on a minion, from installing packages to
  172. detecting information about the system. The only restraint in execution
  173. modules is that the defined functions always return a JSON serializable
  174. object.
  175. Executor
  176. --------
  177. .. toctree::
  178. :maxdepth: 1
  179. :glob:
  180. /ref/executors/index
  181. Executors control how execution modules get called. The default is to just call
  182. them, but this can be customized.
  183. File Server
  184. -----------
  185. The file server module system is used to create file server backends used by the
  186. Salt Master. These modules need to implement the functions used in the
  187. fileserver subsystem. Use the ``gitfs`` module as an example.
  188. See :ref:`File Server Backends <file-server-backends>` for more information.
  189. Grains
  190. ------
  191. * :ref:`writing-grains`
  192. Grain modules define extra routines to populate grains data. All defined
  193. public functions will be executed and MUST return a Python dict object. The
  194. dict keys will be added to the grains made available to the minion.
  195. See :ref:`Grains <grains>` for more.
  196. Log Handler
  197. -----------
  198. Log handlers allows the logs from salt (master or minion) to be sent to log
  199. aggregation systems.
  200. Matcher
  201. -------
  202. Matcher modules are used to define the :ref:`minion targeting expressions <targeting>`.
  203. For now, it is only possible to override the :ref:`existing matchers <matchers>`
  204. (the required CLI plumbing for custom matchers is not implemented yet).
  205. Metaproxy
  206. ---------
  207. Metaproxy is an abstraction layer above the existing proxy minion. It enables
  208. adding different types of proxy minions that can still load existing proxymodules.
  209. Net API
  210. -------
  211. Net API modules are the actual server implementation used by Salt API.
  212. Output
  213. ------
  214. The output modules supply the outputter system with routines to display data
  215. in the terminal. These modules are very simple and only require the `output`
  216. function to execute. The default system outputter is the ``nested`` module.
  217. Pillar
  218. ------
  219. .. toctree::
  220. :maxdepth: 1
  221. :glob:
  222. external_pillars
  223. Used to define optional external pillar systems. The pillar generated via
  224. the filesystem pillar is passed into external pillars. This is commonly used
  225. as a bridge to database data for pillar, but is also the backend to the libvirt
  226. state used to generate and sign libvirt certificates on the fly.
  227. Proxy
  228. -----
  229. :ref:`Proxy Minions <proxy-minion>` are a way to manage devices that cannot run
  230. a full minion directly.
  231. Renderers
  232. ---------
  233. Renderers are the system used to render sls files into salt highdata for the
  234. state compiler. They can be as simple as the ``py`` renderer and as complex as
  235. ``stateconf`` and ``pydsl``.
  236. Returners
  237. ---------
  238. Returners are used to send data from minions to external sources, commonly
  239. databases. A full returner will implement all routines to be supported as an
  240. external job cache. Use the ``redis`` returner as an example.
  241. Roster
  242. ------
  243. The :ref:`Roster system <ssh-roster>` is used by Salt SSH to enumerate devices.
  244. Runners
  245. -------
  246. .. toctree::
  247. :maxdepth: 1
  248. :glob:
  249. /ref/runners/index
  250. Runners are purely master-side execution sequences.
  251. SDB
  252. ---
  253. * :ref:`Writing SDB Modules <sdb-writing-modules>`
  254. SDB is a way to store data that's not associated with a minion. See
  255. :ref:`Storing Data in Other Databases <sdb>`.
  256. Serializer
  257. ----------
  258. Primarily used with :py:func:`file.serialize <salt.states.file.serialize>`.
  259. State
  260. -----
  261. .. toctree::
  262. :maxdepth: 1
  263. :glob:
  264. /ref/states/index
  265. State modules are used to define the state interfaces used by Salt States.
  266. These modules are restrictive in that they must follow a number of rules to
  267. function properly.
  268. .. note::
  269. State modules define the available routines in sls files. If calling
  270. an execution module directly is desired, take a look at the `module`
  271. state.
  272. SPM pkgdb
  273. ---------
  274. * :ref:`SPM Development Guide: Package Database <spm-development-pkgdb>`
  275. pkgdb modules provides storage backends to the package database.
  276. SPM pkgfiles
  277. ------------
  278. * :ref:`SPM Development Guide: Package Database <spm-development-pkgfiles>`
  279. pkgfiles modules handle the actual installation.
  280. SSH Wrapper
  281. -----------
  282. Replacement execution modules for :ref:`Salt SSH <salt-ssh>`.
  283. Thorium
  284. -------
  285. Modules for use in the :ref:`Thorium <thorium-reactor>` event reactor.
  286. Tokens
  287. ------
  288. Token stores for :ref:`External Authentication <acl-eauth>`. See the
  289. :py:mod:`salt.tokens` docstring for details.
  290. .. note::
  291. The runner to load tokens modules is
  292. :py:func:`saltutil.sync_eauth_tokens <salt.runners.saltutil.sync_eauth_tokens>`.
  293. Tops
  294. ----
  295. Tops modules are used to convert external data sources into top file data for
  296. the state system.
  297. Util
  298. ----
  299. Just utility modules to use with other modules via ``__utils__`` (see
  300. :ref:`Dunder Dictionaries <dunder-dictionaries>`).
  301. Wheel
  302. -----
  303. The wheel system is used to manage master side management routines. These
  304. routines are primarily intended for the API to enable master configuration.