1
0

windows.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. .. _windows:
  2. =======
  3. Windows
  4. =======
  5. Salt has full support for running the Salt minion on Windows. You must connect
  6. Windows Salt minions to a Salt master on a supported operating system to
  7. control your Salt Minions.
  8. Many of the standard Salt modules have been ported to work on Windows and many
  9. of the Salt States currently work on Windows as well.
  10. .. _windows-installer:
  11. Installation from the Official SaltStack Repository
  12. ===================================================
  13. **Latest stable build from the selected branch**:
  14. |windownload|
  15. The output of ``md5sum <salt minion exe>`` should match the contents of the
  16. corresponding md5 file.
  17. There are installers available for Python 3. Starting with Salt 3001, only
  18. Python 3 builds of the Windows Salt Minion will be built. Python 2 builds
  19. exist for earlier Salt Minion versions.
  20. .. note::
  21. - `Earlier builds from supported branches
  22. <https://repo.saltstack.com/windows/>`__
  23. Archived builds from unsupported branches:
  24. - `Archive 1 <https://archive.saltstack.com/windows/>`__
  25. - `Archive 2 <https://archive.saltstack.com/windows/archive/>`__
  26. .. note::
  27. The installation executable installs dependencies that the Salt minion
  28. requires.
  29. The 64bit and 32bit installers have been tested on Windows 8.1, Windows Server
  30. 2012 R2, Windows 10, Windows Server 2016, and Windows Server 2019. 32bit
  31. installers have only been tested on 64bit systems. Please file a bug report on
  32. our GitHub repo if issues for other platforms are found.
  33. The installer will detect previous installations of Salt and ask if you would
  34. like to remove them. Clicking OK will remove the Salt binaries and related files
  35. but leave any existing config, cache, and PKI information.
  36. Salt Minion Installation
  37. ========================
  38. If the system is missing the appropriate version of the Visual C++
  39. Redistributable (vcredist) the user will be prompted to install it. Click ``OK``
  40. to install the vcredist. Click ``Cancel`` to abort the installation without
  41. making modifications to the system.
  42. If Salt is already installed on the system the user will be prompted to remove
  43. the previous installation. Click ``OK`` to uninstall Salt without removing the
  44. configuration, PKI information, or cached files. Click ``Cancel`` to abort the
  45. installation before making any modifications to the system.
  46. After the Welcome and the License Agreement, the installer asks for two bits of
  47. information to configure the minion; the master hostname and the minion name.
  48. The installer will update the minion config with these options.
  49. If the installer finds an existing minion config file, these fields will be
  50. populated with values from the existing config, but they will be grayed out.
  51. There will also be a checkbox to use the existing config. If you continue, the
  52. existing config will be used. If the checkbox is unchecked, default values are
  53. displayed and can be changed. If you continue, the existing config file in
  54. ``c:\salt\conf`` will be removed along with the ``c:\salt\conf\minion.d``
  55. directory. The values entered will be used with the default config.
  56. The final page allows you to start the minion service and optionally change its
  57. startup type. By default, the minion is set to ``Automatic``. You can change the
  58. minion start type to ``Automatic (Delayed Start)`` by checking the 'Delayed
  59. Start' checkbox.
  60. .. note::
  61. Highstates that require a reboot may fail after reboot because salt
  62. continues the highstate before Windows has finished the booting process.
  63. This can be fixed by changing the startup type to 'Automatic (Delayed
  64. Start)'. The drawback is that it may increase the time it takes for the
  65. 'salt-minion' service to actually start.
  66. The ``salt-minion`` service will appear in the Windows Service Manager and can
  67. be managed there or from the command line like any other Windows service.
  68. .. code-block:: bat
  69. sc start salt-minion
  70. net start salt-minion
  71. Installation Prerequisites
  72. --------------------------
  73. Most Salt functionality should work just fine right out of the box. A few Salt
  74. modules rely on PowerShell. The minimum version of PowerShell required for Salt
  75. is version 3. If you intend to work with DSC then Powershell version 5 is the
  76. minimum.
  77. .. _windows-installer-options:
  78. Silent Installer Options
  79. ========================
  80. The installer can be run silently by providing the ``/S`` option at the command
  81. line. The installer also accepts the following options for configuring the Salt
  82. Minion silently:
  83. ========================= =====================================================
  84. Option Description
  85. ========================= =====================================================
  86. ``/master=`` A string value to set the IP address or hostname of
  87. the master. Default value is 'salt'. You can pass a
  88. single master or a comma-separated list of masters.
  89. Setting the master will cause the installer to use
  90. the default config or a custom config if defined.
  91. ``/minion-name=`` A string value to set the minion name. Default value
  92. is 'hostname'. Setting the minion name causes the
  93. installer to use the default config or a custom
  94. config if defined.
  95. ``/start-minion=`` Either a 1 or 0. '1' will start the salt-minion
  96. service, '0' will not. Default is to start the
  97. service after installation.
  98. ``/start-minion-delayed`` Set the minion start type to
  99. ``Automatic (Delayed Start)``.
  100. ``/default-config`` Overwrite the existing config if present with the
  101. default config for salt. Default is to use the
  102. existing config if present. If ``/master`` and/or
  103. ``/minion-name`` is passed, those values will be used
  104. to update the new default config.
  105. ``/custom-config=`` A string value specifying the name of a custom config
  106. file in the same path as the installer or the full
  107. path to a custom config file. If ``/master`` and/or
  108. ``/minion-name`` is passed, those values will be used
  109. to update the new custom config.
  110. ``/S`` Runs the installation silently. Uses the above
  111. settings or the defaults.
  112. ``/?`` Displays command line help.
  113. ========================= =====================================================
  114. .. note::
  115. ``/start-service`` has been deprecated but will continue to function as
  116. expected for the time being.
  117. .. note::
  118. ``/default-config`` and ``/custom-config=`` will backup an existing config
  119. if found. A timestamp and a ``.bak`` extension will be added. That includes
  120. the ``minion`` file and the ``minion.d`` directory.
  121. Here are some examples of using the silent installer:
  122. .. code-block:: bat
  123. # Install the Salt Minion
  124. # Configure the minion and start the service
  125. Salt-Minion-3001-Py3-AMD64-Setup.exe /S /master=yoursaltmaster /minion-name=yourminionname
  126. .. code-block:: bat
  127. # Install the Salt Minion
  128. # Configure the minion but don't start the minion service
  129. Salt-Minion-3001-Py3-AMD64-Setup.exe /S /master=yoursaltmaster /minion-name=yourminionname /start-minion=0
  130. .. code-block:: bat
  131. # Install the Salt Minion
  132. # Configure the minion using a custom config and configuring multimaster
  133. Salt-Minion-3001-Py3-AMD64-Setup.exe /S /custom-config=windows_minion /master=prod_master1,prod_master2
  134. Running the Salt Minion on Windows as an Unprivileged User
  135. ==========================================================
  136. Notes:
  137. - These instructions were tested with Windows Server 2008 R2
  138. - They are generalizable to any version of Windows that supports a salt-minion
  139. Create the Unprivileged User that the Salt Minion will Run As
  140. -------------------------------------------------------------
  141. 1. Click ``Start`` > ``Control Panel`` > ``User Accounts``.
  142. 2. Click ``Add or remove user accounts``.
  143. 3. Click ``Create new account``.
  144. 4. Enter ``salt-user`` (or a name of your preference) in the ``New account name`` field.
  145. 5. Select the ``Standard user`` radio button.
  146. 6. Click the ``Create Account`` button.
  147. 7. Click on the newly created user account.
  148. 8. Click the ``Create a password`` link.
  149. 9. In the ``New password`` and ``Confirm new password`` fields, provide
  150. a password (e.g "SuperSecretMinionPassword4Me!").
  151. 10. In the ``Type a password hint`` field, provide appropriate text (e.g. "My Salt Password").
  152. 11. Click the ``Create password`` button.
  153. 12. Close the ``Change an Account`` window.
  154. Add the New User to the Access Control List for the Salt Folder
  155. ---------------------------------------------------------------
  156. 1. In a File Explorer window, browse to the path where Salt is installed (the default path is ``C:\Salt``).
  157. 2. Right-click on the ``Salt`` folder and select ``Properties``.
  158. 3. Click on the ``Security`` tab.
  159. 4. Click the ``Edit`` button.
  160. 5. Click the ``Add`` button.
  161. 6. Type the name of your designated Salt user and click the ``OK`` button.
  162. 7. Check the box to ``Allow`` the ``Modify`` permission.
  163. 8. Click the ``OK`` button.
  164. 9. Click the ``OK`` button to close the ``Salt Properties`` window.
  165. Update the Windows Service User for the ``salt-minion`` Service
  166. ---------------------------------------------------------------
  167. 1. Click ``Start`` > ``Administrative Tools`` > ``Services``.
  168. 2. In the Services list, right-click on ``salt-minion`` and select ``Properties``.
  169. 3. Click the ``Log On`` tab.
  170. 4. Click the ``This account`` radio button.
  171. 5. Provide the account credentials created in section A.
  172. 6. Click the ``OK`` button.
  173. 7. Click the ``OK`` button to the prompt confirming that the user ``has been
  174. granted the Log On As A Service right``.
  175. 8. Click the ``OK`` button to the prompt confirming that ``The new logon name
  176. will not take effect until you stop and restart the service``.
  177. 9. Right-Click on ``salt-minion`` and select ``Stop``.
  178. 10. Right-Click on ``salt-minion`` and select ``Start``.
  179. .. _building-developing-windows:
  180. Building and Developing on Windows
  181. ==================================
  182. This document will explain how to set up a development environment for Salt on
  183. Windows. The development environment allows you to work with the source code to
  184. customize or fix bugs. It will also allow you to build your own installation.
  185. There are several scripts to automate creating a Windows installer as well as
  186. setting up an environment that facilitates developing and troubleshooting Salt
  187. code. They are located in the ``pkg\windows`` directory in the Salt repo
  188. `(here) <https://github.com/saltstack/salt/tree/|repo_primary_branch|/pkg/windows>`_.
  189. Scripts:
  190. --------
  191. =================== ===========
  192. Script Description
  193. =================== ===========
  194. ``build_env_2.ps1`` A PowerShell script that sets up a Python 2 build
  195. environment
  196. ``build_env_3.ps1`` A PowerShell script that sets up a Python 3 build
  197. environment
  198. ``build_pkg.bat`` A batch file that builds a Windows installer based on the
  199. contents of the ``C:\Python27`` directory
  200. ``build.bat`` A batch file that fully automates the building of the
  201. Windows installer using the above two scripts
  202. =================== ===========
  203. .. note::
  204. The ``build.bat`` and ``build_pkg.bat`` scripts both accept a parameter to
  205. specify the version of Salt that will be displayed in the Windows installer.
  206. If no version is passed, the version will be determined using git.
  207. Both scripts also accept an additional parameter to specify the version of
  208. Python to use. The default is 2.
  209. Prerequisite Software
  210. ---------------------
  211. The only prerequisite is `Git for Windows <https://git-scm.com/download/win/>`_.
  212. .. _create-build-environment:
  213. Create a Build Environment
  214. --------------------------
  215. 1. Working Directory
  216. ^^^^^^^^^^^^^^^^^^^^
  217. Create a ``Salt-Dev`` directory on the root of ``C:``. This will be our working
  218. directory. Navigate to ``Salt-Dev`` and clone the
  219. `Salt <https://github.com/saltstack/salt/>`_ repo from GitHub.
  220. Open a command line and type:
  221. .. code-block:: bat
  222. cd \
  223. md Salt-Dev
  224. cd Salt-Dev
  225. git clone https://github.com/saltstack/salt
  226. Go into the ``salt`` directory and checkout the version of salt to work with
  227. (2016.3 or higher).
  228. .. code-block:: bat
  229. cd salt
  230. git checkout 2017.7.2
  231. 2. Setup the Python Environment
  232. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  233. Navigate to the ``pkg\windows`` directory and execute the **build_env.ps1**
  234. PowerShell script.
  235. .. code-block:: bat
  236. cd pkg\windows
  237. powershell -file build_env_2.ps1
  238. .. note::
  239. You can also do this from Explorer by navigating to the ``pkg\windows``
  240. directory, right clicking the **build_env_2.ps1** powershell script and
  241. selecting **Run with PowerShell**
  242. This will download and install Python 2 with all the dependencies needed to
  243. develop and build Salt.
  244. .. note::
  245. If you get an error or the script fails to run you may need to change the
  246. execution policy. Open a powershell window and type the following command:
  247. .. code-block:: powershell
  248. Set-ExecutionPolicy RemoteSigned
  249. 3. Salt in Editable Mode
  250. ^^^^^^^^^^^^^^^^^^^^^^^^
  251. Editable mode allows you to more easily modify and test the source code. For
  252. more information see the `Pip documentation
  253. <https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs>`_.
  254. Navigate to the root of the ``salt`` directory and install Salt in editable mode
  255. with ``pip``
  256. .. code-block:: bat
  257. cd \Salt-Dev\salt
  258. pip install -e .
  259. .. note::
  260. The ``.`` is important
  261. .. note::
  262. If ``pip`` is not recognized, you may need to restart your shell to get the
  263. updated path
  264. .. note::
  265. If ``pip`` is still not recognized make sure that the Python Scripts folder
  266. is in the System ``%PATH%``. (``C:\Python2\Scripts``)
  267. 4. Setup Salt Configuration
  268. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  269. Salt requires a minion configuration file and a few other directories. The
  270. default config file is named ``minion`` located in ``C:\salt\conf``. The
  271. easiest way to set this up is to copy the contents of the
  272. ``salt\pkg\windows\buildenv`` directory to ``C:\salt``.
  273. .. code-block:: bat
  274. cd \
  275. md salt
  276. xcopy /s /e \Salt-Dev\salt\pkg\windows\buildenv\* \salt\
  277. Now go into the ``C:\salt\conf`` directory and edit the minion config file named
  278. ``minion`` (no extension). You need to configure the master and id parameters in
  279. this file. Edit the following lines:
  280. .. code-block:: bat
  281. master: <ip or name of your master>
  282. id: <name of your minion>
  283. .. _create-windows-installer:
  284. Create a Windows Installer
  285. ==========================
  286. To create a Windows installer, follow steps 1 and 2 from
  287. :ref:`Create a Build Environment <create-build-environment>` above. Then proceed
  288. to 3 below:
  289. 3. Install Salt
  290. ---------------
  291. To create the installer for Window we install Salt using Python instead of pip.
  292. Navigate to the root ``salt`` directory and install Salt.
  293. .. code-block:: bat
  294. cd \Salt-Dev\salt
  295. python setup.py install
  296. 4. Create the Windows Installer
  297. -------------------------------
  298. Navigate to the ``pkg\windows`` directory and run the ``build_pkg.bat``
  299. with the build version (2017.7.2) and the Python version as parameters.
  300. .. code-block:: bat
  301. cd pkg\windows
  302. build_pkg.bat 2017.7.2 2
  303. ^^^^^^^^ ^
  304. | |
  305. # build version -- |
  306. # python version ------
  307. .. note::
  308. If no version is passed, the ``build_pkg.bat`` will guess the version number
  309. using git. If the python version is not passed, the default is 2.
  310. .. _create-windows-installer-easy:
  311. Creating a Windows Installer: Alternate Method (Easier)
  312. =======================================================
  313. Clone the `Salt <https://github.com/saltstack/salt/>`_ repo from GitHub into the
  314. directory of your choice. We're going to use ``Salt-Dev``.
  315. .. code-block:: bat
  316. cd \
  317. md Salt-Dev
  318. cd Salt-Dev
  319. git clone https://github.com/saltstack/salt
  320. Go into the ``salt`` directory and checkout the version of Salt you want to
  321. build.
  322. .. code-block:: bat
  323. cd salt
  324. git checkout 2017.7.2
  325. Then navigate to ``pkg\windows`` and run the ``build.bat`` script with the
  326. version you're building.
  327. .. code-block:: bat
  328. cd pkg\windows
  329. build.bat 2017.7.2 3
  330. ^^^^^^^^ ^
  331. | |
  332. # build version |
  333. # python version --
  334. This will install everything needed to build a Windows installer for Salt using
  335. Python 3. The binary will be in the ``salt\pkg\windows\installer`` directory.
  336. .. _test-salt-minion:
  337. Testing the Salt minion
  338. =======================
  339. 1. Create the directory ``C:\salt`` (if it doesn't exist already)
  340. 2. Copy the example ``conf`` and ``var`` directories from
  341. ``pkg\windows\buildenv`` into ``C:\salt``
  342. 3. Edit ``C:\salt\conf\minion``
  343. .. code-block:: bash
  344. master: ipaddress or hostname of your salt-master
  345. 4. Start the salt-minion
  346. .. code-block:: bash
  347. cd C:\Python27\Scripts
  348. python salt-minion -l debug
  349. 5. On the salt-master accept the new minion's key
  350. .. code-block:: bash
  351. sudo salt-key -A
  352. This accepts all unaccepted keys. If you're concerned about security just
  353. accept the key for this specific minion.
  354. 6. Test that your minion is responding
  355. On the salt-master run:
  356. .. code-block:: bash
  357. sudo salt '*' test.version
  358. You should get the following response: ``{'your minion hostname': True}``
  359. Packages Management Under Windows 2003
  360. ======================================
  361. Windows Server 2003 and Windows XP have both reached End of Support. Though Salt
  362. is not officially supported on operating systems that are EoL, some
  363. functionality may continue to work.
  364. On Windows Server 2003, you need to install optional component "WMI Windows
  365. Installer Provider" to get a full list of installed packages. If you don't have
  366. this, salt-minion can't report some installed software.