1
0

index.rst 14 KB

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