external_cache.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. .. _external-job-cache:
  2. =========================================
  3. Storing Job Results in an External System
  4. =========================================
  5. After a job executes, job results are returned
  6. to the Salt Master by each Salt Minion. These results are stored in the
  7. :ref:`Default Job Cache <default_job_cache>`.
  8. In addition to the Default Job Cache, Salt provides two additional
  9. mechanisms to send job results to other systems (databases, local syslog,
  10. and others):
  11. * External Job Cache
  12. * Master Job Cache
  13. The major difference between these two mechanism is from where results are
  14. returned (from the Salt Master or Salt Minion). Configuring either of these
  15. options will also make the :py:mod:`Jobs Runner functions <salt.runners.jobs>`
  16. to automatically query the remote stores for information.
  17. External Job Cache - Minion-Side Returner
  18. -----------------------------------------
  19. When an External Job Cache is configured, data is returned to the Default Job
  20. Cache on the Salt Master like usual, and then results are also sent to an
  21. External Job Cache using a Salt returner module running on the Salt Minion.
  22. .. image:: /_static/external-job-cache.png
  23. :align: center
  24. * Advantages: Data is stored without placing additional load on the Salt Master.
  25. * Disadvantages: Each Salt Minion connects to the external job cache, which can
  26. result in a large number of connections. Also requires additional configuration to
  27. get returner module settings on all Salt Minions.
  28. Master Job Cache - Master-Side Returner
  29. ---------------------------------------
  30. .. versionadded:: 2014.7.0
  31. Instead of configuring an External Job Cache on each Salt Minion, you can
  32. configure the Master Job Cache to send job results from the Salt Master
  33. instead. In this configuration, Salt Minions send data to the Default Job Cache
  34. as usual, and then the Salt Master sends the data to the external system using
  35. a Salt returner module running on the Salt Master.
  36. .. image:: /_static/master-job-cache.png
  37. :align: center
  38. * Advantages: A single connection is required to the external system. This is
  39. preferred for databases and similar systems.
  40. * Disadvantages: Places additional load on your Salt Master.
  41. Configure an External or Master Job Cache
  42. -----------------------------------------
  43. Step 1: Understand Salt Returners
  44. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  45. Before you configure a job cache, it is essential to understand Salt returner
  46. modules ("returners"). Returners are pluggable Salt Modules that take the data
  47. returned by jobs, and then perform any necessary steps to send the data to an
  48. external system. For example, a returner might establish a connection,
  49. authenticate, and then format and transfer data.
  50. The Salt Returner system provides the core functionality used by the External
  51. and Master Job Cache systems, and the same returners are used by both systems.
  52. Salt currently provides many different returners that let you connect to a
  53. wide variety of systems. A complete list is available at
  54. :ref:`all Salt returners <all-salt.returners>`.
  55. Each returner is configured differently, so make sure you read and follow the
  56. instructions linked from that page.
  57. For example, the MySQL returner requires:
  58. * A database created using provided schema (structure is available at
  59. :mod:`MySQL returner <salt.returners.mysql>`)
  60. * A user created with privileges to the database
  61. * Optional SSL configuration
  62. A simpler returner, such as Slack or HipChat, requires:
  63. * An API key/version
  64. * The target channel/room
  65. * The username that should be used to send the message
  66. Step 2: Configure the Returner
  67. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  68. After you understand the configuration and have the external system ready, the
  69. configuration requirements must be declared.
  70. External Job Cache
  71. """"""""""""""""""
  72. The returner configuration settings can be declared in the Salt Minion
  73. configuration file, the Minion's pillar data, or the Minion's grains.
  74. If ``external_job_cache`` configuration settings are specified in more than
  75. one place, the options are retrieved in the following order. The first
  76. configuration location that is found is the one that will be used.
  77. - Minion configuration file
  78. - Minion's grains
  79. - Minion's pillar data
  80. Master Job Cache
  81. """"""""""""""""
  82. The returner configuration settings for the Master Job Cache should be
  83. declared in the Salt Master's configuration file.
  84. Configuration File Examples
  85. """""""""""""""""""""""""""
  86. MySQL requires:
  87. .. code-block:: yaml
  88. mysql.host: 'salt'
  89. mysql.user: 'salt'
  90. mysql.pass: 'salt'
  91. mysql.db: 'salt'
  92. mysql.port: 3306
  93. Slack requires:
  94. .. code-block:: yaml
  95. slack.channel: 'channel'
  96. slack.api_key: 'key'
  97. slack.from_name: 'name'
  98. After you have configured the returner and added settings to the configuration
  99. file, you can enable the External or Master Job Cache.
  100. Step 3: Enable the External or Master Job Cache
  101. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  102. Configuration is a single line that specifies an
  103. already-configured returner to use to send all job data to an external system.
  104. External Job Cache
  105. """"""""""""""""""
  106. To enable a returner as the External Job Cache (Minion-side), add the following
  107. line to the Salt Master configuration file:
  108. .. code-block:: yaml
  109. ext_job_cache: <returner>
  110. For example:
  111. .. code-block:: yaml
  112. ext_job_cache: mysql
  113. .. note::
  114. When configuring an External Job Cache (Minion-side), the returner settings are
  115. added to the Minion configuration file, but the External Job Cache setting
  116. is configured in the Master configuration file.
  117. Master Job Cache
  118. """"""""""""""""
  119. To enable a returner as a Master Job Cache (Master-side), add the following
  120. line to the Salt Master configuration file:
  121. .. code-block:: yaml
  122. master_job_cache: <returner>
  123. For example:
  124. .. code-block:: yaml
  125. master_job_cache: mysql
  126. Verify that the returner configuration settings are in the Master configuration
  127. file, and be sure to restart the salt-master service after you make
  128. configuration changes. (``service salt-master restart``).