1
0

index.rst 14 KB

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