minionfs.rst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. .. _tutorial-minionfs:
  2. ============================
  3. MinionFS Backend Walkthrough
  4. ============================
  5. .. versionadded:: 2014.1.0
  6. .. note::
  7. This walkthrough assumes basic knowledge of Salt and :mod:`cp.push
  8. <salt.modules.cp.push>`. To get up to speed, check out the
  9. :ref:`Salt Walkthrough <tutorial-salt-walk-through>`.
  10. Sometimes it is desirable to deploy a file located on one minion to one or more
  11. other minions. This is supported in Salt, and can be accomplished in two parts:
  12. #. Minion support for pushing files to the master (using :py:func:`cp.push
  13. <salt.modules.cp.push>`)
  14. #. The :mod:`minionfs <salt.fileserver.minionfs>` fileserver backend
  15. This walkthrough will show how to use both of these features.
  16. Enabling File Push
  17. ==================
  18. To set the master to accept files pushed from minions, the
  19. :conf_master:`file_recv` option in the master config file must be set to
  20. ``True`` (the default is ``False``).
  21. .. code-block:: yaml
  22. file_recv: True
  23. .. note::
  24. This change requires a restart of the salt-master service.
  25. Pushing Files
  26. =============
  27. Once this has been done, files can be pushed to the master using the
  28. :py:func:`cp.push <salt.modules.cp.push>` function:
  29. .. code-block:: bash
  30. salt 'minion-id' cp.push /path/to/the/file
  31. This command will store the file in a subdirectory named ``minions`` under the
  32. master's :conf_master:`cachedir`. On most masters, this path will be
  33. ``/var/cache/salt/master/minions``. Within this directory will be one directory
  34. for each minion which has pushed a file to the master, and underneath that the
  35. full path to the file on the minion. So, for example, if a minion with an ID of
  36. ``dev1`` pushed a file ``/var/log/myapp.log`` to the master, it would be saved
  37. to ``/var/cache/salt/master/minions/dev1/var/log/myapp.log``.
  38. Serving Pushed Files Using MinionFS
  39. ===================================
  40. While it is certainly possible to add ``/var/cache/salt/master/minions`` to the
  41. master's :conf_master:`file_roots` and serve these files, it may only be
  42. desirable to expose files pushed from certain minions. Adding
  43. ``/var/cache/salt/master/minions/<minion-id>`` for each minion that needs to be
  44. exposed can be cumbersome and prone to errors.
  45. Enter :mod:`minionfs <salt.fileserver.minionfs>`. This fileserver backend will
  46. make files pushed using :py:func:`cp.push <salt.modules.cp.push>` available to
  47. the Salt fileserver, and provides an easy mechanism to restrict which minions'
  48. pushed files are made available.
  49. Simple Configuration
  50. --------------------
  51. To use the :mod:`minionfs <salt.fileserver.minionfs>` backend, add ``minionfs``
  52. to the list of backends in the :conf_master:`fileserver_backend` configuration
  53. option on the master:
  54. .. code-block:: yaml
  55. file_recv: True
  56. fileserver_backend:
  57. - roots
  58. - minionfs
  59. .. note::
  60. ``minion`` also works here. Prior to the 2018.3.0 release, *only*
  61. ``minion`` would work.
  62. Also, as described earlier, ``file_recv: True`` is needed to enable the
  63. master to receive files pushed from minions. As always, changes to the
  64. master configuration require a restart of the ``salt-master`` service.
  65. Files made available via :mod:`minionfs <salt.fileserver.minionfs>` are by
  66. default located at ``salt://<minion-id>/path/to/file``. Think back to the
  67. earlier example, in which ``dev1`` pushed a file ``/var/log/myapp.log`` to the
  68. master. With :mod:`minionfs <salt.fileserver.minionfs>` enabled, this file
  69. would be addressable in Salt at ``salt://dev1/var/log/myapp.log``.
  70. If many minions have pushed to the master, this will result in many directories
  71. in the root of the Salt fileserver. For this reason, it is recommended to use
  72. the :conf_master:`minionfs_mountpoint` config option to organize these files
  73. underneath a subdirectory:
  74. .. code-block:: yaml
  75. minionfs_mountpoint: salt://minionfs
  76. Using the above mountpoint, the file in the example would be located at
  77. ``salt://minionfs/dev1/var/log/myapp.log``.
  78. Restricting Certain Minions' Files from Being Available Via MinionFS
  79. --------------------------------------------------------------------
  80. A whitelist and blacklist can be used to restrict the minions whose pushed
  81. files are available via :mod:`minionfs <salt.fileserver.minionfs>`. These lists
  82. can be managed using the :conf_master:`minionfs_whitelist` and
  83. :conf_master:`minionfs_blacklist` config options. Click the links for both of
  84. them for a detailed explanation of how to use them.
  85. A more complex configuration example, which uses both a whitelist and
  86. blacklist, can be found below:
  87. .. code-block:: yaml
  88. file_recv: True
  89. fileserver_backend:
  90. - roots
  91. - minionfs
  92. minionfs_mountpoint: salt://minionfs
  93. minionfs_whitelist:
  94. - host04
  95. - web*
  96. - 'mail\d+\.domain\.tld'
  97. minionfs_blacklist:
  98. - web21
  99. Potential Concerns
  100. ------------------
  101. * There is no access control in place to restrict which minions have access to
  102. files served up by :mod:`minionfs <salt.fileserver.minionfs>`. All minions
  103. will have access to these files.
  104. * Unless the :conf_master:`minionfs_whitelist` and/or
  105. :conf_master:`minionfs_blacklist` config options are used, all minions which
  106. push files to the master will have their files made available via
  107. :mod:`minionfs <salt.fileserver.minionfs>`.