index.rst 14 KB

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