windows-package-manager.rst 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596
  1. .. _windows-package-manager:
  2. #######################
  3. Windows Package Manager
  4. #######################
  5. Introduction
  6. ************
  7. The Windows Package Manager provides a software repository and a package manager
  8. similar to what is provided by ``yum`` and ``apt`` on Linux. This tool enables
  9. the installation of software on remote Windows systems.
  10. The repository contains a collection of software definition files. A software
  11. definition file is a YAML/JINJA file with an ``.sls`` file extension. It
  12. contains all the information Salt needs to install a software package on a
  13. Windows system, including the download location of the installer, required
  14. command-line switches for silent install, etc.
  15. Software definition files can be hosted in one or more Git repositories. The
  16. default repository is hosted on GitHub by SaltStack. It is maintained by
  17. SaltStack and the Salt community and contains software definition files for many
  18. common Windows packages. Anyone is welcome to submit a pull request to this
  19. repo to add new software definitions. The default github repository is:
  20. - `salt-winrepo-ng <https://github.com/saltstack/salt-winrepo-ng>`_
  21. The Windows Package Manager is used the same way as other package managers Salt
  22. is aware of. For example:
  23. - the ``pkg.installed`` and similar states work on Windows.
  24. - the ``pkg.install`` and similar module functions work on Windows.
  25. High level differences to ``yum`` and ``apt`` are:
  26. - The repository metadata (SLS files) can be managed through either Salt or git
  27. - Packages can be downloaded from within the Salt repository, a git repository
  28. or from HTTP(S) or FTP URLs
  29. - No dependencies are managed. Dependencies between packages need to be managed
  30. manually
  31. Requirements
  32. ============
  33. If using the a software definition files hosted on a Git repo, the following
  34. libraries are required:
  35. - GitPython 0.3 or later
  36. or
  37. - pygit2 0.20.3 with libgit 0.20.0 or later
  38. Quick Start
  39. ***********
  40. You can get up and running with winrepo pretty quickly just using the defaults.
  41. Assuming no changes to the default configuration (ie, ``file_roots``) run the
  42. following commands on the master:
  43. .. code-block:: bash
  44. salt-run winrepo.update_git_repos
  45. salt * pkg.refresh_db
  46. salt * pkg.install firefox_x64
  47. On a masterless minion run the following:
  48. .. code-block:: bash
  49. salt-call --local winrepo.update_git_repos
  50. salt-call --local pkg.refresh_db
  51. salt-call --local pkg.install firefox_x64
  52. These commands clone the default winrepo from github, update the winrepo
  53. database on the minion, and install the latest version of Firefox.
  54. Configuration
  55. *************
  56. The Github repository (winrepo) is synced to the ``file_roots`` in a location
  57. specified by the ``winrepo_dir_ng`` setting in the config. The default value of
  58. ``winrepo_dir_ng`` is as follows:
  59. - Linux master: ``/srv/salt/win/repo-ng`` (``salt://win/repo-ng``)
  60. - Masterless minion: ``C:\salt\srv\salt\win\repo-ng`` (``salt://win/repo-ng``)
  61. Master Configuration
  62. ====================
  63. The following are settings are available for configuring the winrepo on the
  64. master:
  65. - :conf_master:`winrepo_dir`
  66. - :conf_master:`winrepo_dir_ng`
  67. - :conf_master:`winrepo_remotes`
  68. - :conf_master:`winrepo_remotes_ng`
  69. - :conf_master:`winrepo_branch`
  70. - :conf_master:`winrepo_provider`
  71. - :conf_master:`winrepo_ssl_verify`
  72. See :ref:`here <winrepo-master-config-opts>` for detailed information on all
  73. master config options for winrepo.
  74. winrepo_dir
  75. -----------
  76. :conf_master:`winrepo_dir` (str)
  77. This setting is maintained for backwards compatibility with legacy minions. It
  78. points to the location in the ``file_roots`` where the winrepo files are kept.
  79. The default is: ``/srv/salt/win/repo``
  80. winrepo_dir_ng
  81. --------------
  82. :conf_master:`winrepo_dir_ng` (str)
  83. The location in the ``file_roots`` where the winrepo files are kept. The default
  84. is ``/srv/salt/win/repo-ng``.
  85. .. warning::
  86. You can change the location of the winrepo directory. However, it must
  87. always be set to a path that is inside the ``file_roots``.
  88. Otherwise the software definition files will be unreachable by the minion.
  89. .. important::
  90. A common mistake is to change the ``file_roots`` setting and fail to update
  91. the ``winrepo_dir_ng`` and ``winrepo_dir`` settings so that they are inside
  92. the ``file_roots``
  93. winrepo_remotes
  94. ---------------
  95. :conf_master:`winrepo_remotes` (list)
  96. This setting is maintained for backwards compatibility with legacy minions. It
  97. points to the legacy git repo. The default is a list containing a single URL:
  98. `https://github.com/saltstack/salt-winrepo
  99. <https://github.com/saltstack/salt-winrepo>`_
  100. The legacy repo can be disabled by setting it to an empty list in the master
  101. config.
  102. .. code-block:: bash
  103. winrepo_remotes: []
  104. winrepo_remotes_ng
  105. ------------------
  106. :conf_master:`winrepo_remotes_ng` (list)
  107. This setting tells the ``winrepo.upgate_git_repos`` command where the next
  108. generation winrepo is hosted. This a list of URLs to multiple git repos. The
  109. default is a list containing a single URL:
  110. `https://github.com/saltstack/salt-winrepo-ng
  111. <https://github.com/saltstack/salt-winrepo-ng>`_
  112. winrepo_refspecs
  113. ----------------
  114. :conf_master:`winrepo_refspecs` (list)
  115. Specify what references to fetch from remote repositories. The default is
  116. ``['+refs/heads/*:refs/remotes/origin/*', '+refs/tags/*:refs/tags/*']``
  117. winrepo_branch
  118. --------------
  119. :conf_master:`winrepo_branch` (str)
  120. The branch of the git repo to checkout. The default is ``master``
  121. winrepo_provider
  122. ----------------
  123. :conf_master:`winrepo_provider` (str)
  124. The provider to be used for winrepo. Default is ``pygit2``. Falls back to
  125. ``gitpython`` when ``pygit2`` is not available
  126. winrepo_ssl_verify
  127. ------------------
  128. :conf_master:`winrepo_ssl_verify` (bool)
  129. Ignore SSL certificate errors when contacting remote repository. Default is
  130. ``False``
  131. Master Configuration (pygit2)
  132. =============================
  133. The following configuration options only apply when the
  134. :conf_master:`winrepo_provider` option is set to ``pygit2``.
  135. - :conf_master:`winrepo_insecure_auth`
  136. - :conf_master:`winrepo_passphrase`
  137. - :conf_master:`winrepo_password`
  138. - :conf_master:`winrepo_privkey`
  139. - :conf_master:`winrepo_pubkey`
  140. - :conf_master:`winrepo_user`
  141. winrepo_insecure_auth
  142. ---------------------
  143. :conf_master:`winrepo_insecure_auth` (bool)
  144. Used only with ``pygit2`` provider. Whether or not to allow insecure auth.
  145. Default is ``False``
  146. winrepo_passphrase
  147. ------------------
  148. :conf_master:`winrepo_passphrase` (str)
  149. Used only with ``pygit2`` provider. Used when the SSH key being used to
  150. authenticate is protected by a passphrase. Default is ``''``
  151. winrepo_privkey
  152. ---------------
  153. :conf_master:`winrepo_privkey` (str)
  154. Used only with ``pygit2`` provider. Used with :conf_master:`winrepo_pubkey` to
  155. authenticate to SSH remotes. Default is ``''``
  156. winrepo_pubkey
  157. --------------
  158. :conf_master:`winrepo_pubkey` (str)
  159. Used only with ``pygit2`` provider. Used with :conf_master:`winrepo_privkey` to
  160. authenticate to SSH remotes. Default is ``''``
  161. winrepo_user
  162. ------------
  163. :conf_master:`winrepo_user` (str)
  164. Used only with ``pygit2`` provider. Used with :conf_master:`winrepo_password` to
  165. authenticate to HTTPS remotes. Default is ``''``
  166. winrepo_password
  167. ----------------
  168. :conf_master:`winrepo_password` (str)
  169. Used only with ``pygit2`` provider. Used with :conf_master:`winrepo_user` to
  170. authenticate to HTTPS remotes. Default is ``''``
  171. Minion Configuration
  172. ====================
  173. Refreshing the package definitions can take some time, these options were
  174. introduced to allow more control of when it occurs. These settings apply to all
  175. minions whether in masterless mode or not.
  176. - :conf_minion:`winrepo_cache_expire_max`
  177. - :conf_minion:`winrepo_cache_expire_min`
  178. - :conf_minion:`winrepo_cachefile`
  179. - :conf_minion:`winrepo_source_dir`
  180. winrepo_cache_expire_max
  181. ------------------------
  182. :conf_minion:`winrepo_cache_expire_max` (int)
  183. Sets the maximum age in seconds of the winrepo metadata file to avoid it
  184. becoming stale. If the metadata file is older than this setting it will trigger
  185. a ``pkg.refresh_db`` on the next run of any ``pkg`` module function that
  186. requires the metadata file. Default is 604800 (1 week).
  187. Software package definitions are automatically refreshed if stale after
  188. :conf_minion:`winrepo_cache_expire_max`. Running a highstate normal forces the
  189. refresh of the package definition and generation of the metadata, unless
  190. the metadata is younger than :conf_minion:`winrepo_cache_expire_max`.
  191. winrepo_cache_expire_min
  192. ------------------------
  193. :conf_minion:`winrepo_cache_expire_min` (int)
  194. Sets the minimum age in seconds of the winrepo metadata file to avoid refreshing
  195. too often. If the metadata file is older than this setting the metadata will be
  196. refreshed unless you pass ``refresh: False`` in the state. Default is 1800
  197. (30 min).
  198. winrepo_cachefile
  199. -----------------
  200. :conf_minion:`winrepo_cachefile` (str)
  201. The file name of the winrepo cache file. The file is placed at the root of
  202. ``winrepo_dir_ng``. Default is ``winrepo.p``.
  203. winrepo_source_dir
  204. ------------------
  205. :conf_minion:`winrepo_source_dir` (str)
  206. The location of the .sls files on the Salt file server. This allows for using
  207. different environments. Default is ``salt://win/repo-ng/``.
  208. .. warning::
  209. If the default for ``winrepo_dir_ng`` is changed, this setting may need to
  210. changed on each minion. The default setting for ``winrepo_dir_ng`` is
  211. ``/srv/salt/win/repo-ng``. If that were changed to ``/srv/salt/new/repo-ng``
  212. then the ``winrepo_source_dir`` would need to be changed to
  213. ``salt://new/repo-ng``
  214. Masterless Minion Configuration
  215. ===============================
  216. The following are settings are available for configuring the winrepo on a
  217. masterless minion:
  218. - :conf_minion:`winrepo_dir`
  219. - :conf_minion:`winrepo_dir_ng`
  220. - :conf_minion:`winrepo_remotes`
  221. - :conf_minion:`winrepo_remotes_ng`
  222. See :ref:`here <winrepo-minion-config-opts>` for detailed information on all
  223. minion config options for winrepo.
  224. winrepo_dir
  225. -----------
  226. :conf_minion:`winrepo_dir` (str)
  227. This setting is maintained for backwards compatibility with legacy minions. It
  228. points to the location in the ``file_roots`` where the winrepo files are kept.
  229. The default is: ``C:\salt\srv\salt\win\repo``
  230. winrepo_dir_ng
  231. --------------
  232. :conf_minion:`winrepo_dir_ng` (str)
  233. The location in the ``file_roots where the winrepo files are kept. The default
  234. is ``C:\salt\srv\salt\win\repo-ng``.
  235. .. warning::
  236. You can change the location of the winrepo directory. However, it must
  237. always be set to a path that is inside the ``file_roots``.
  238. Otherwise the software definition files will be unreachable by the minion.
  239. .. important::
  240. A common mistake is to change the ``file_roots`` setting and fail to update
  241. the ``winrepo_dir_ng`` and ``winrepo_dir`` settings so that they are inside
  242. the ``file_roots``. You might also want to verify ``winrepo_source_dir`` on
  243. the minion as well.
  244. winrepo_remotes
  245. ---------------
  246. :conf_minion:`winrepo_remotes` (list)
  247. This setting is maintained for backwards compatibility with legacy minions. It
  248. points to the legacy git repo. The default is a list containing a single URL:
  249. `https://github.com/saltstack/salt-winrepo
  250. <https://github.com/saltstack/salt-winrepo>`_
  251. The legacy repo can be disabled by setting it to an empty list in the minion
  252. config.
  253. .. code-block:: bash
  254. winrepo_remotes: []
  255. winrepo_remotes_ng
  256. ------------------
  257. :conf_minion:`winrepo_remotes_ng` (list)
  258. This setting tells the ``winrepo.upgate_git_repos`` command where the next
  259. generation winrepo is hosted. This a list of URLs to multiple git repos. The
  260. default is a list containing a single URL:
  261. `https://github.com/saltstack/salt-winrepo-ng
  262. <https://github.com/saltstack/salt-winrepo-ng>`_
  263. Initialization
  264. **************
  265. Populate the Local Repository
  266. =============================
  267. The SLS files used to install Windows packages are not distributed by default
  268. with Salt. Use the :mod:`winrepo.update_git_repos <salt.runners.winrepo.update_git_repos>`
  269. runner initialize the repository in the location specified by ``winrepo_dir_ng``
  270. in the master config. This will pull the software definition files down from the
  271. git repository.
  272. .. code-block:: bash
  273. salt-run winrepo.update_git_repos
  274. If running a minion in masterless mode, the same command can be run using
  275. ``salt-call``. The repository will be initialized in the location specified by
  276. ``winrepo_dir_ng`` in the minion config.
  277. .. code-block:: bash
  278. salt-call --local winrepo.update_git_repos
  279. These commands will also sync down the legacy repo to maintain backwards
  280. compatibility with legacy minions. See :ref:`Legacy Minions <legacy-minions>`
  281. The legacy repo can be disabled by setting it to an empty list in the master or
  282. minion config.
  283. .. code-block:: bash
  284. winrepo_remotes: []
  285. Generate the Metadata File (Legacy)
  286. ===================================
  287. This step is only required if you are supporting legacy minions. In current
  288. usage the metadata file is generated on the minion in the next step, Update
  289. the Minion Database. For legacy minions the metadata file is generated on the
  290. master using the :mod:`winrepo.genrepo <salt.runners.winrepo.genrepo>` runner.
  291. .. code-block:: bash
  292. salt-run winrepo.genrepo
  293. Update the Minion Database
  294. ==========================
  295. Run :mod:`pkg.refresh_db <salt.modules.win_pkg.refresh_db>` on each of your
  296. Windows minions to synchronize the package repository to the minion and build
  297. the package database.
  298. .. code-block:: bash
  299. # From the master
  300. salt -G 'os:windows' pkg.refresh_db
  301. # From the minion in masterless mode
  302. salt-call --local pkg.refresh_db
  303. The above command returns the following summary denoting the number of packages
  304. that succeeded or failed to compile:
  305. .. code-block:: bash
  306. local:
  307. ----------
  308. failed:
  309. 0
  310. success:
  311. 301
  312. total:
  313. 301
  314. .. note::
  315. This command can take a few minutes to complete as the software definition
  316. files are copied to the minion and the database is generated.
  317. .. note::
  318. Use ``pkg.refresh_db`` when developing new Windows package definitions to
  319. check for errors in the definitions against one or more Windows minions.
  320. Usage
  321. *****
  322. After completing the configuration and initialization steps, you are ready to
  323. manage software on your Windows minions.
  324. .. note::
  325. The following example commands can be run from the master using ``salt`` or
  326. on a masterless minion using ``salt-call``
  327. List Installed Packages
  328. =======================
  329. You can get a list of packages installed on the system using
  330. :mod:`pkg.list_pkgs <salt.modules.win_pkg.list_pkgs>`.
  331. .. code-block:: bash
  332. # From the master
  333. salt -G 'os:windows' pkg.list_pkgs
  334. # From the minion in masterless mode
  335. salt-call --local pkg.list_pkgs
  336. This will return all software installed on the system whether it is managed by
  337. Salt or not as shown below:
  338. .. code-block:: bash
  339. local:
  340. ----------
  341. Frhed 1.6.0:
  342. 1.6.0
  343. GNU Privacy Guard:
  344. 2.2.16
  345. Gpg4win (3.1.9):
  346. 3.1.9
  347. git:
  348. 2.17.1.2
  349. nsis:
  350. 3.03
  351. python3_x64:
  352. 3.7.4150.0
  353. salt-minion-py3:
  354. 2019.2.3
  355. You can tell by how the software name is displayed which software is managed by
  356. Salt and which software is not. When Salt finds a match in the winrepo database
  357. it displays the short name as defined in the software definition file. It is
  358. usually a single-word, lower-case name. All other software names will be
  359. displayed with the full name as they are shown in Add/Remove Programs. So, in
  360. the return above, you can see that Git (git), Nullsoft Installer (nsis), Python
  361. 3.7 (python3_x64) and Salt (salt-minion-py3) all have a corresponding software
  362. definition file. The others do not.
  363. List Available Versions
  364. =======================
  365. You can query the available version of a package using
  366. :mod:`pkg.list_available <salt.modules.win_pkg.list_available>` and passing the
  367. name of the software:
  368. .. code-block:: bash
  369. # From the master
  370. salt winminion pkg.list_available firefox_x64
  371. # From the minion in masterless mode
  372. salt-call --local pkg.list_available firefox_x64
  373. The above command will return the following:
  374. .. code-block:: bash
  375. winminion:
  376. - 69.0
  377. - 69.0.1
  378. - 69.0.2
  379. - 69.0.3
  380. - 70.0
  381. - 70.0.1
  382. - 71.0
  383. - 72.0
  384. - 72.0.1
  385. - 72.0.2
  386. - 73.0
  387. - 73.0.1
  388. - 74.0
  389. As you can see, there are many versions of Firefox available for installation.
  390. You can refer to a software package by its ``name`` or its ``full_name``
  391. surrounded by quotes.
  392. .. note::
  393. From a Linux master it is OK to use single-quotes. However, the ``cmd``
  394. shell on Windows requires you to use double-quotes when wrapping strings
  395. that may contain spaces. Powershell seems to accept either one.
  396. Install a Package
  397. =================
  398. You can install a package using :mod:`pkg.install <salt.modules.win_pkg.install>`:
  399. .. code-block:: bash
  400. # From the master
  401. salt winminion pkg.install 'firefox_x64'
  402. # From the minion in masterless mode
  403. salt-call --local pkg.install "firefox_x64"
  404. The above will install the latest version of Firefox.
  405. .. code-block:: bash
  406. # From the master
  407. salt winminion pkg.install 'firefox_x64' version=74.0
  408. # From the minion in masterless mode
  409. salt-call --local pkg.install "firefox_x64" version=74.0
  410. The above will install version 74.0 of Firefox.
  411. If a different version of the package is already installed it will be replaced
  412. with the version in the winrepo (only if the package itself supports live
  413. updating).
  414. You can also specify the full name:
  415. .. code-block:: bash
  416. # From the master
  417. salt winminion pkg.install 'Mozilla Firefox 17.0.1 (x86 en-US)'
  418. # From the minion in masterless mode
  419. salt-call --local pkg.install "Mozilla Firefox 17.0.1 (x86 en-US)"
  420. Remove a Package
  421. ================
  422. You can uninstall a package using :mod:`pkg.remove <salt.modules.win_pkg.remove>`:
  423. .. code-block:: bash
  424. # From the master
  425. salt winminion pkg.remove firefox_x64
  426. # From the minion in masterless mode
  427. salt-call --local pkg.remove firefox_x64
  428. .. _software-definition-files:
  429. Software Definition Files
  430. *************************
  431. A software definition file is a YAML/JINJA2 file that contains all the
  432. information needed to install a piece of software using Salt. It defines
  433. information about the package to include version, full name, flags required for
  434. the installer and uninstaller, whether or not to use the Windows task scheduler
  435. to install the package, where to download the installation package, etc.
  436. Directory Structure and Naming
  437. ==============================
  438. The files are stored in the location designated by the ``winrepo_dir_ng``
  439. setting. All files in this directory that have a ``.sls`` file extension are
  440. considered software definition files. The files are evaluated to create the
  441. metadata file on the minion.
  442. You can maintain standalone software definition files that point to software on
  443. other servers or on the internet. In this case the file name would be the short
  444. name of the software with the ``.sls`` extension, ie ``firefox.sls``.
  445. You can also store the binaries for your software together with their software
  446. definition files in their own directory. In this scenario, the directory name
  447. would be the short name for the software and the software definition file would
  448. be inside that directory and named ``init.sls``.
  449. Look at the following example directory structure on a Linux master assuming
  450. default config settings:
  451. .. code-block:: bash
  452. srv/
  453. |---salt/
  454. | |---win/
  455. | | |---repo-ng/
  456. | | | |---custom_defs/
  457. | | | | |---ms_office_2013_x64/
  458. | | | | | |---access.en-us/
  459. | | | | | |---excel.en-us/
  460. | | | | | |---outlook.en-us/
  461. | | | | | |---powerpoint.en-us/
  462. | | | | | |---word.en-us/
  463. | | | | | |---init.sls
  464. | | | | | |---setup.dll
  465. | | | | | |---setup.exe
  466. | | | | |---openssl.sls
  467. | | | | |---zoom.sls
  468. | | | |---salt-winrepo-ng/
  469. | | | | |---auditbeat/
  470. | | | | | |---init.sls
  471. | | | | | |---install.cmd
  472. | | | | | |---install.ps1
  473. | | | | | |---remove.cmd
  474. | | | | |---gpg4win/
  475. | | | | | |---init.sls
  476. | | | | | |---silent.ini
  477. | | | | |---7zip.sls
  478. | | | | |---adobereader.sls
  479. | | | | |---audacity.sls
  480. | | | | |---ccleaner.sls
  481. | | | | |---chrome.sls
  482. | | | | |---firefox.sls
  483. In the above directory structure, the user has created the ``custom_defs``
  484. directory in which to store their custom software definition files. In that
  485. directory you see a folder for MS Office 2013 that contains all the installer
  486. files along with a software definition file named ``init.sls``. The user has
  487. also created two more standalone software definition files; ``openssl.sls`` and
  488. ``zoom.sls``.
  489. The ``salt-winrepo-ng`` directory is created by the ``winrepo.update_git_repos``
  490. command. This folder contains the clone of the git repo designated by the
  491. ``winrepo_remotes_ng`` config setting.
  492. .. warning::
  493. It is recommended that the user not modify the files in the
  494. ``salt-winrepo-ng`` directory as it will break future runs of
  495. ``winrepo.update_git_repos``.
  496. .. warning::
  497. It is recommended that the user not place any custom software definition
  498. files in the ``salt-winrepo-ng`` directory. The ``winrepo.update_git_repos``
  499. command wipes out the contents of the ``salt-winrepo-ng`` directory each
  500. time it is run. Any extra files stored there will be lost.
  501. Writing Software Definition Files
  502. =================================
  503. A basic software definition file is really easy to write if you already know
  504. some basic things about your software:
  505. - The full name as shown in Add/Remove Programs
  506. - The exact version number as shown in Add/Remove Programs
  507. - How to install your software silently from the command line
  508. The software definition file itself is just a data structure written in YAML.
  509. The top level item is a short name that Salt will use to reference the software.
  510. There can be only one short name in the file and it must be unique across all
  511. software definition files in the repo. This is the name that will be used to
  512. install/remove the software. It is also the name that will appear when Salt
  513. finds a match in the repo when running ``pkg.list_pkgs``.
  514. The next indentation level is the version number. There can be many of these,
  515. but they must be unique within the file. This is also displayed in
  516. ``pkg.list_pkgs``.
  517. The last indentation level contains the information Salt needs to actually
  518. install the software. Available parameters are:
  519. - ``full_name`` : The full name as displayed in Add/Remove Programs
  520. - ``installer`` : The location of the installer binary
  521. - ``install_flags`` : The flags required to install silently
  522. - ``uninstaller`` : The location of the uninstaller binary
  523. - ``uninstall_flags`` : The flags required to uninstall silently
  524. - ``msiexec`` : Use msiexec to install this package
  525. - ``allusers`` : If this is an MSI, install to all users
  526. - ``cache_dir`` : Cache the entire directory in the installer URL (``salt://``)
  527. - ``cache_file`` : Cache a single file in the installer URL (``salt://``)
  528. - ``use_scheduler`` : Launch the installer using the task scheduler
  529. - ``source_hash`` : The hash sum for the installer
  530. Usage of these parameters is demonstrated in the following examples and
  531. discussed in more detail below. To understand these examples you'll need a basic
  532. understanding of Jinja. The following links have some basic tips and best
  533. practices for working with Jinja in Salt:
  534. `Understanding Jinja <https://docs.saltstack.com/en/latest/topics/jinja/index.html>`_
  535. `Jinja <https://docs.saltstack.com/en/getstarted/config/jinja.html>`_
  536. Example: Basic
  537. ==============
  538. Take a look at this basic, pure YAML example for a software definition file for
  539. Firefox:
  540. .. code-block:: yaml
  541. firefox_x64:
  542. '74.0':
  543. full_name: Mozilla Firefox 74.0 (x64 en-US)
  544. installer: 'https://download-installer.cdn.mozilla.net/pub/firefox/releases/74.0/win64/en-US/Firefox%20Setup%2074.0.exe'
  545. install_flags: '/S'
  546. uninstaller: '%ProgramFiles(x86)%/Mozilla Firefox/uninstall/helper.exe'
  547. uninstall_flags: '/S'
  548. '73.0.1':
  549. full_name: Mozilla Firefox 73.0.1 (x64 en-US)
  550. installer: 'https://download-installer.cdn.mozilla.net/pub/firefox/releases/73.0.1/win64/en-US/Firefox%20Setup%2073.0.1.exe'
  551. install_flags: '/S'
  552. uninstaller: '%ProgramFiles(x86)%/Mozilla Firefox/uninstall/helper.exe'
  553. uninstall_flags: '/S'
  554. You can see the first item is the short name for the software, in this case
  555. ``firefox_x64``. It is the first line in the definition. The next line is
  556. indented two spaces and contains the software ``version``. The lines following
  557. the ``version`` are indented two more spaces and contain all the information
  558. needed to install the Firefox package.
  559. .. important::
  560. The package name must be unique to all other packages in the software
  561. repository. The ``full_name`` combined with the version must also be unique.
  562. They must also match exactly what is shown in Add/Remove Programs
  563. (``appwiz.cpl``).
  564. .. important::
  565. The version number must be enclosed in quotes, otherwise the YAML parser
  566. will remove trailing zeros. For example, `74.0` will just become `74`.
  567. As you can see in the example above, a software definition file can define
  568. multiple versions for the same piece of software. These are denoted by putting
  569. the next version number at the same indentation level as the first with its
  570. software definition information indented below it.
  571. Example: Jinja
  572. ==============
  573. When there are tens or hundreds of versions available for a piece of software
  574. definition file can become quite large. This is a scenario where Jinja can be
  575. helpful. Consider the following software definition file for Firefox using
  576. Jinja:
  577. .. code-block:: jinja
  578. {%- set lang = salt['config.get']('firefox:pkg:lang', 'en-US') %}
  579. firefox_x64:
  580. {% for version in ['74.0',
  581. '73.0.1', '73.0',
  582. '72.0.2', '72.0.1', '72.0',
  583. '71.0', '70.0.1', '70.0',
  584. '69.0.3', '69.0.2', '69.0.1'] %}
  585. '{{ version }}':
  586. full_name: 'Mozilla Firefox {{ version }} (x64 {{ lang }})'
  587. installer: 'https://download-installer.cdn.mozilla.net/pub/firefox/releases/{{ version }}/win64/{{ lang }}/Firefox%20Setup%20{{ version }}.exe'
  588. install_flags: '/S'
  589. uninstaller: '%ProgramFiles%\Mozilla Firefox\uninstall\helper.exe'
  590. uninstall_flags: '/S'
  591. {% endfor %}
  592. In this example we are able to generate a software definition file that defines
  593. how to install 12 versions of Firefox. We use Jinja to create a list of
  594. available versions. That list is in a ``for loop`` where each version is placed
  595. in the ``version`` variable. The version is inserted everywhere there is a
  596. ``{{ version }}`` marker inside the ``for loop``.
  597. You'll notice that there is a single variable (``lang``) defined at the top of
  598. the software definition. Because these files are going through the Salt renderer
  599. many Salt modules are exposed via the ``salt`` keyword. In this case it is
  600. calling the ``config.get`` function to get a language setting that can be placed
  601. in the minion config. If it is not there, it defaults to ``en-US``.
  602. Example: Latest
  603. ===============
  604. There are some software vendors that do not provide access to all versions of
  605. their software. Instead they provide a single URL to what is always the latest
  606. version. In some cases the software keeps itself up to date. One example of this
  607. is the Google Chrome web browser.
  608. `Chrome <https://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi>`_
  609. To handle situations such as these, set the version to `latest`. Here's an
  610. example:
  611. .. code-block:: yaml
  612. chrome:
  613. latest:
  614. full_name: 'Google Chrome'
  615. installer: 'https://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi'
  616. install_flags: '/qn /norestart'
  617. uninstaller: 'https://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi'
  618. uninstall_flags: '/qn /norestart'
  619. msiexec: True
  620. The above example shows us two things. First it demonstrates the usage of
  621. ``latest`` as the version. In this case Salt will install the version of Chrome
  622. at the URL and report that version.
  623. The second thing to note is that this is installing software using an MSI. You
  624. can see that ``msiexec`` is set to ``True``.
  625. Example: MSI Patch
  626. ==================
  627. When the ``msiexec`` parameter is set to ``True`` it uses the ``/i`` option for
  628. installs and the ``/x`` option for uninstalls. This is problematic when trying
  629. to install an MSI patch which requires the ``/p`` option. You can't combine the
  630. ``/i`` and ``/p`` options. So how do you apply a patch to installed software in
  631. winrepo using an ``.msp`` file?
  632. One wiley contributor came up with the following solution to this problem by
  633. using the ``%cd%`` environment variable. Consider the following software
  634. definition file:
  635. .. code-block:: yaml
  636. MyApp:
  637. '1.0':
  638. full_name: MyApp
  639. installer: 'salt://win/repo-ng/MyApp/MyApp.1.0.msi'
  640. install_flags: '/qn /norestart'
  641. uninstaller: '{B5B5868F-23BA-297A-917D-0DF345TF5764}'
  642. uninstall_flags: '/qn /norestart'
  643. msiexec: True
  644. '1.1':
  645. full_name: MyApp
  646. installer: 'salt://win/repo-ng/MyApp/MyApp.1.0.msi'
  647. install_flags: '/qn /norestart /update "%cd%\\MyApp.1.1.msp" '
  648. uninstaller: '{B5B5868F-23BA-297A-917D-0DF345TF5764}'
  649. uninstall_flags: '/qn /norestart'
  650. msiexec: True
  651. cache_file: salt://win/repo/MyApp/MyApp.1.1.msp
  652. There are a few things to note about this software definition file. First, is
  653. the solution we are trying to solve, that of applying a patch. Version ``1.0``
  654. just installs the application using the ``1.0`` MSI defined in the ``installer``
  655. parameter. There is nothing special in the ``install_flags`` and nothing is
  656. cached.
  657. Version ``1.1`` uses the same installer, but uses the ``cache_file`` option to
  658. specify a single file to cache. In order for this to work the MSP file needs to
  659. be in the same directory as the MSI file on the ``file_roots``.
  660. The final step to getting this to work is to add the additional ``/update`` flag
  661. to the ``install_flags`` parameter. Add the path to the MSP file using the
  662. ``%cd%`` environment variable. ``%cd%`` resolves to the current working
  663. directory which is the location in the minion cache where the installer file is
  664. cached.
  665. See issue `#32780 <https://github.com/saltstack/salt/issues/32780>`_ for more
  666. details.
  667. This same approach could be used for applying MST files for MSIs and answer
  668. files for other types of .exe based installers.
  669. Parameters
  670. ==========
  671. These are the parameters that can be used to generate a software definition
  672. file. These parameters are all placed under the ``version`` in the software
  673. definition file:
  674. Example usage can be found on the `github repo
  675. <https://github.com/saltstack/salt-winrepo-ng>`_
  676. full_name (str)
  677. ---------------
  678. This is the full name for the software as shown in "Programs and Features" in
  679. the control panel. You can also get this information by installing the package
  680. manually and then running ``pkg.list_pkgs``. Here's an example of the output
  681. from ``pkg.list_pkgs``:
  682. .. code-block:: bash
  683. salt 'test-2008' pkg.list_pkgs
  684. test-2008
  685. ----------
  686. 7-Zip 9.20 (x64 edition):
  687. 9.20.00.0
  688. Mozilla Firefox 74.0 (x64 en-US)
  689. 74.0
  690. Mozilla Maintenance Service:
  691. 74.0
  692. salt-minion-py3:
  693. 3001
  694. Notice the Full Name for Firefox: ``Mozilla Firefox 74.0 (x64 en-US)``. That's
  695. exactly what should be in the ``full_name`` parameter in the software definition
  696. file.
  697. If any of the software installed on the machine matches the full name defined in
  698. one of the software definition files in the repository the package name will be
  699. returned. The example below shows the ``pkg.list_pkgs`` for a machine that has
  700. Mozilla Firefox 74.0 installed and a software definition for that version of
  701. Firefox.
  702. .. code-block:: bash
  703. test-2008:
  704. ----------
  705. 7zip:
  706. 9.20.00.0
  707. Mozilla Maintenance Service:
  708. 74.0
  709. firefox_x64:
  710. 74.0
  711. salt-minion-py3:
  712. 3001
  713. .. important::
  714. The version number and ``full_name`` need to match the output from
  715. ``pkg.list_pkgs`` exactly so that the installation status can be verified
  716. by the state system.
  717. .. note::
  718. It is still possible to successfully install packages using ``pkg.install``,
  719. even if the ``full_name`` or the version number don't match exactly. The
  720. module will complete successfully, but continue to display the full name
  721. in ``pkg.list_pkgs``. If this is happening, verify that the ``full_name``
  722. and the ``version`` match exactly what is displayed in Add/Remove
  723. Programs.
  724. .. tip::
  725. To force Salt to display the full name when there's already an existing
  726. package definition file on the system, you can pass a bogus ``saltenv``
  727. parameter to the command like so: ``pkg.list_pkgs saltenv=NotARealEnv``
  728. .. tip::
  729. It's important use :mod:`pkg.refresh_db <salt.modules.win_pkg.refresh_db>`
  730. to check for errors and ensure the latest package definition is on any
  731. minion you're testing new definitions on.
  732. installer (str)
  733. ---------------
  734. This is the path to the binary (``.exe``, ``.msi``) that will install the
  735. package. This can be a local path or a URL. If it is a URL or a Salt path
  736. (``salt://``), the package will be cached locally and then executed. If it is a
  737. path to a file on disk or a file share, it will be executed directly.
  738. .. note::
  739. When storing software in the same location as the winrepo it is usually best
  740. practice to place each installer in its own directory rather than in the
  741. root of winrepo.
  742. Best practice is to create a sub folder named after the package. That folder
  743. will contain the software definition file named ``init.sls``. The binary
  744. installer should be stored in that directory as well if you're hosting those
  745. files on the file_roots.
  746. ``pkg.refresh_db`` will process all ``.sls`` files in all sub directories
  747. in the ``winrepo_dir_ng`` directory.
  748. install_flags (str)
  749. -------------------
  750. This setting contains any flags that need to be passed to the installer to make
  751. it perform a silent install. These can often be found by adding ``/?`` or ``/h``
  752. when running the installer from the command-line. A great resource for finding
  753. these silent install flags is the WPKG project wiki_:
  754. .. warning::
  755. Salt will appear to hang if the installer is expecting user input. So it is
  756. imperative that the software have the ability to install silently.
  757. uninstaller (str)
  758. -----------------
  759. This is the path to the program used to uninstall this software. This can be the
  760. path to the same ``exe`` or ``msi`` used to install the software. Exe
  761. uninstallers are pretty straight forward. MSIs, on the other hand, can be
  762. handled a couple different ways. You can use the GUID for the software to
  763. uninstall or you can use the same MSI used to install the software.
  764. You can usually find uninstall information in the registry:
  765. - Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall
  766. - Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall
  767. Here's an example using the GUID to uninstall software.
  768. .. code-block:: yaml
  769. 7zip:
  770. '9.20.00.0':
  771. full_name: 7-Zip 9.20 (x64 edition)
  772. installer: salt://win/repo-ng/7zip/7z920-x64.msi
  773. install_flags: '/qn /norestart'
  774. uninstaller: '{23170F69-40C1-2702-0920-000001000000}'
  775. uninstall_flags: '/qn /norestart'
  776. msiexec: True
  777. Here's an example using the same MSI used to install the software:
  778. .. code-block:: yaml
  779. 7zip:
  780. '9.20.00.0':
  781. full_name: 7-Zip 9.20 (x64 edition)
  782. installer: salt://win/repo-ng/7zip/7z920-x64.msi
  783. install_flags: '/qn /norestart'
  784. uninstaller: salt://win/repo-ng/7zip/7z920-x64.msi
  785. uninstall_flags: '/qn /norestart'
  786. msiexec: True
  787. uninstall_flags (str)
  788. ---------------------
  789. This setting contains any flags that need to be passed to the uninstaller to
  790. make it perform a silent uninstall. These can often be found by adding ``/?`` or
  791. ``/h`` when running the uninstaller from the command-line. A great resource for
  792. finding these silent install flags the WPKG project wiki_:
  793. .. warning::
  794. Salt will appear to hang if the uninstaller is expecting user input. So it
  795. is imperative that the software have the ability to uninstall silently.
  796. msiexec (bool, str)
  797. -------------------
  798. This tells Salt to use ``msiexec /i`` to install the package and ``msiexec /x``
  799. to uninstall. This is for ``.msi`` installations only.
  800. Possible options are:
  801. - True
  802. - False (default)
  803. - the path to ``msiexec.exe`` on your system
  804. .. code-block:: yaml
  805. 7zip:
  806. '9.20.00.0':
  807. full_name: 7-Zip 9.20 (x64 edition)
  808. installer: salt://win/repo/7zip/7z920-x64.msi
  809. install_flags: '/qn /norestart'
  810. uninstaller: salt://win/repo/7zip/7z920-x64.msi
  811. uninstall_flags: '/qn /norestart'
  812. msiexec: 'C:\Windows\System32\msiexec.exe'
  813. allusers (bool)
  814. ---------------
  815. This parameter is specific to ``.msi`` installations. It tells ``msiexec`` to
  816. install the software for all users. The default is ``True``.
  817. cache_dir (bool)
  818. ----------------
  819. This setting requires the software to be stored on the ``file_roots`` and only
  820. applies to URLs that begin with ``salt://``. If ``True`` the entire directory
  821. where the installer resides will be recursively cached. This is useful for
  822. installers that depend on other files in the same directory for installation.
  823. .. warning::
  824. Be aware that all files and directories in the same location as the
  825. installer file will be copied down to the minion. If you place your
  826. software definition file in the root of winrepo (``/srv/salt/win/repo-ng``)
  827. and it contains ``cache_dir: True`` the entire contents of winrepo will be
  828. cached to the minion. Therefore, it is best practice to place your installer
  829. files in a subdirectory if they are to be stored in winrepo.
  830. Here's an example using cache_dir:
  831. .. code-block:: yaml
  832. sqlexpress:
  833. '12.0.2000.8':
  834. full_name: Microsoft SQL Server 2014 Setup (English)
  835. installer: 'salt://win/repo/sqlexpress/setup.exe'
  836. install_flags: '/ACTION=install /IACCEPTSQLSERVERLICENSETERMS /Q'
  837. cache_dir: True
  838. cache_file (str)
  839. ----------------
  840. This setting requires the file to be stored on the ``file_roots`` and only
  841. applies to URLs that begin with ``salt://``. It indicates a single file to copy
  842. down for use with the installer. It is copied to the same location as the
  843. installer. Use this over ``cache_dir`` if there are many files in the directory
  844. and you only need a specific file and don't want to cache additional files that
  845. may reside in the installer directory.
  846. use_scheduler (bool)
  847. --------------------
  848. If set to ``True``, Windows will use the task scheduler to run the installation.
  849. A one-time task will be created in the task scheduler and launched. The return
  850. to the minion will be that the task was launched successfully, not that the
  851. software was installed successfully.
  852. .. note::
  853. This is used by the software definition for Salt itself. The first thing the
  854. Salt installer does is kill the Salt service, which then kills all child
  855. processes. If the Salt installer is launched via Salt, then the installer
  856. itself is killed leaving Salt on the machine but not running. Use of the
  857. task scheduler allows an external process to launch the Salt installation so
  858. its processes aren't killed when the Salt service is stopped.
  859. source_hash (str)
  860. -----------------
  861. This tells Salt to compare a hash sum of the installer to the provided hash sum
  862. before execution. The value can be formatted as ``<hash_algorithm>=<hash_sum>``,
  863. or it can be a URI to a file containing the hash sum.
  864. For a list of supported algorithms, see the `hashlib documentation
  865. <https://docs.python.org/2/library/hashlib.html>`_.
  866. Here's an example using ``source_hash``:
  867. .. code-block:: yaml
  868. messageanalyzer:
  869. '4.0.7551.0':
  870. full_name: 'Microsoft Message Analyzer'
  871. installer: 'salt://win/repo/messageanalyzer/MessageAnalyzer64.msi'
  872. install_flags: '/quiet /norestart'
  873. uninstaller: '{1CC02C23-8FCD-487E-860C-311EC0A0C933}'
  874. uninstall_flags: '/quiet /norestart'
  875. msiexec: True
  876. source_hash: 'sha1=62875ff451f13b10a8ff988f2943e76a4735d3d4'
  877. Not Implemented
  878. ---------------
  879. The following parameters are often seen in the software definition files hosted
  880. on the Git repo. However, they are not implemented and have no effect on the
  881. installation process.
  882. :param bool reboot: Not implemented
  883. :param str locale: Not implemented
  884. .. _standalone-winrepo:
  885. Managing Windows Software on a Standalone Windows Minion
  886. ********************************************************
  887. The Windows Software Repository functions similarly in a standalone environment,
  888. with a few differences in the configuration.
  889. To replace the winrepo runner that is used on the Salt master, an
  890. :mod:`execution module <salt.modules.win_repo>` exists to provide the same
  891. functionality to standalone minions. The functions are named the same as the
  892. ones in the runner, and are used in the same way; the only difference is that
  893. ``salt-call`` is used instead of ``salt-run``:
  894. .. code-block:: bash
  895. salt-call winrepo.update_git_repos
  896. salt-call pkg.refresh_db
  897. After executing the previous commands the repository on the standalone system is
  898. ready for use.
  899. .. _winrepo-troubleshooting:
  900. Troubleshooting
  901. ***************
  902. My software installs correctly but pkg.installed says it failed
  903. ===============================================================
  904. If you have a package that seems to install properly, but Salt reports a failure
  905. then it is likely you have a ``version`` or ``full_name`` mismatch.
  906. Check the exact ``full_name`` and ``version`` as shown in Add/Remove Programs
  907. (``appwiz.cpl``). Use ``pkg.list_pkgs`` to check that the ``full_name`` and
  908. ``version`` exactly match what is installed. Make sure the software definition
  909. file has the exact value for ``full_name`` and that the version matches exactly.
  910. Also, make sure the version is wrapped in single quotes in the software
  911. definition file.
  912. Changes to sls files not being picked up
  913. ========================================
  914. You may have recently updated some of the software definition files on the repo.
  915. Ensure you have refreshed the database on the minion.
  916. .. code-block:: bash
  917. salt winminion pkg.refresh_db
  918. How Success and Failure are Reported by pkg.installed
  919. =====================================================
  920. The install state/module function of the Windows package manager works roughly
  921. as follows:
  922. 1. Execute ``pkg.list_pkgs`` to get a list of software currently on the machine
  923. 2. Compare the requested version with the installed version
  924. 3. If versions are the same, report no changes needed
  925. 4. Install the software as described in the software definition file
  926. 5. Execute ``pkg.list_pkgs`` to get a new list of software currently on the
  927. machine
  928. 6. Compare the requested version with the new installed version
  929. 7. If versions are the same, report success
  930. 8. If versions are different, report failure
  931. Winrepo Upgrade Issues
  932. ======================
  933. To minimize potential issues, it is a good idea to remove any winrepo git
  934. repositories that were checked out by the legacy (pre-2015.8.0) winrepo code
  935. when upgrading the master to 2015.8.0 or later. Run
  936. :mod:`winrepo.update_git_repos <salt.runners.winrepo.update_git_repos>` to
  937. clone them anew after the master is started.
  938. pygit2_/GitPython_ Support for Maintaining Git Repos
  939. ****************************************************
  940. The :mod:`winrepo.update_git_repos <salt.runners.winrepo.update_git_repos>`
  941. runner now makes use of the same underlying code used by the :ref:`Git Fileserver Backend <tutorial-gitfs>`
  942. and :mod:`Git External Pillar <salt.pillar.git_pillar>` to maintain and update
  943. its local clones of git repositories. If a compatible version of either pygit2_
  944. (0.20.3 and later) or GitPython_ (0.3.0 or later) is installed, Salt will use it
  945. instead of the old method (which invokes the :mod:`git.latest <salt.states.git.latest>`
  946. state).
  947. .. note::
  948. If compatible versions of both pygit2_ and GitPython_ are installed, then
  949. Salt will prefer pygit2_. To override this behavior use the
  950. :conf_master:`winrepo_provider` configuration parameter:
  951. .. code-block:: yaml
  952. winrepo_provider: gitpython
  953. The :mod:`winrepo execution module <salt.modules.win_repo>` (discussed
  954. above in the :ref:`Managing Windows Software on a Standalone Windows Minion
  955. <standalone-winrepo>` section) does not yet officially support the new
  956. pygit2_/GitPython_ functionality, but if either pygit2_ or GitPython_ is
  957. installed into Salt's bundled Python then it *should* work. However, it
  958. should be considered experimental at this time.
  959. Accessing Authenticated Git Repos (pygit2)
  960. ******************************************
  961. Support for pygit2 added the ability to access authenticated git repositories
  962. and to set per-remote config settings. An example of this would be the
  963. following:
  964. .. code-block:: yaml
  965. winrepo_remotes:
  966. - https://github.com/saltstack/salt-winrepo.git
  967. - git@github.com:myuser/myrepo.git:
  968. - pubkey: /path/to/key.pub
  969. - privkey: /path/to/key
  970. - passphrase: myaw3s0m3pa$$phr4$3
  971. - https://github.com/myuser/privaterepo.git:
  972. - user: mygithubuser
  973. - password: CorrectHorseBatteryStaple
  974. .. note::
  975. Per-remote configuration settings work in the same fashion as they do in
  976. gitfs, with global parameters being overridden by their per-remote
  977. counterparts. For instance, setting :conf_master:`winrepo_passphrase` would
  978. set a global passphrase for winrepo that would apply to all SSH-based
  979. remotes, unless overridden by a ``passphrase`` per-remote parameter.
  980. See :ref:`here <gitfs-per-remote-config>` for more a more in-depth
  981. explanation of how per-remote configuration works in gitfs. The same
  982. principles apply to winrepo.
  983. Maintaining Git Repos
  984. *********************
  985. A ``clean`` argument has been added to the
  986. :mod:`winrepo.update_git_repos <salt.runners.winrepo.update_git_repos>`
  987. runner. When ``clean`` is ``True`` it will tell the runner to dispose of
  988. directories under the :conf_master:`winrepo_dir_ng`/:conf_minion:`winrepo_dir_ng`
  989. which are not explicitly configured. This prevents the need to manually remove
  990. these directories when a repo is removed from the config file. To clean these
  991. old directories, just pass ``clean=True``:
  992. .. code-block:: bash
  993. salt-run winrepo.update_git_repos clean=True
  994. If a mix of git and non-git Windows Repo definition files are being used, then
  995. this should *not* be used, as it will remove the directories containing non-git
  996. definitions.
  997. Name Collisions Between Repos
  998. *****************************
  999. Collisions between repo names are now detected. The
  1000. :mod:`winrepo.update_git_repos <salt.runners.winrepo.update_git_repos>`
  1001. runner will not proceed if any are detected. Consider the following
  1002. configuration:
  1003. .. code-block:: yaml
  1004. winrepo_remotes:
  1005. - https://foo.com/bar/baz.git
  1006. - https://mydomain.tld/baz.git
  1007. - https://github.com/foobar/baz
  1008. The :mod:`winrepo.update_git_repos <salt.runners.winrepo.update_git_repos>`
  1009. runner will refuse to update repos here, as all three of these repos would be
  1010. checked out to the same directory. To work around this, a per-remote parameter
  1011. called ``name`` can be used to resolve these conflicts:
  1012. .. code-block:: yaml
  1013. winrepo_remotes:
  1014. - https://foo.com/bar/baz.git
  1015. - https://mydomain.tld/baz.git:
  1016. - name: baz_junior
  1017. - https://github.com/foobar/baz:
  1018. - name: baz_the_third
  1019. .. _legacy-minions:
  1020. Legacy Minions
  1021. **************
  1022. The Windows Package Manager was upgraded with breaking changes starting with
  1023. Salt 2015.8.0. To maintain backwards compatibility Salt continues to support
  1024. older minions.
  1025. The breaking change was to generate the winrepo database on the minion instead
  1026. of the master. This allowed for the use of Jinja in the software definition
  1027. files. It enabled the use of pillar, grains, execution modules, etc. during
  1028. compile time. To support this new functionality, a next-generation (ng) repo was
  1029. created.
  1030. See the :ref:`Changes in Version 2015.8.0 <2015-8-0-winrepo-changes>` for
  1031. details.
  1032. On prior versions of Salt, or legacy minions, the winrepo database was
  1033. generated on the master and pushed down to the minions. Any grains exposed at
  1034. compile time would have been those of the master and not the minion.
  1035. The repository for legacy minions is named ``salt-winrepo`` and is located at:
  1036. - https://github.com/saltstack/salt-winrepo
  1037. Legacy Configuration
  1038. ====================
  1039. Winrepo settings were changed with the introduction of the Next Generation (ng)
  1040. of winrepo.
  1041. Legacy Master Config Options
  1042. ----------------------------
  1043. There were three options available for a legacy master to configure winrepo.
  1044. Unless you're running a legacy master as well, you shouldn't need to configure
  1045. any of these.
  1046. - ``win_gitrepos``
  1047. - ``win_repo``
  1048. - ``win_repo_mastercachefile``
  1049. ``win_gitrepos``: (list)
  1050. A list of URLs to github repos. Default is a list with a single URL:
  1051. - 'https://github.com/saltstack/salt-winrepo.git'
  1052. ``win_repo``: (str)
  1053. The location on the master to store the winrepo. The default is
  1054. ``/srv/salt/win/repo``.
  1055. ``win_repo_mastercachefile``: (str)
  1056. The location on the master to generate the winrepo database file. The default is
  1057. ``/srv/salt/win/repo/winrep.p``
  1058. Legacy Minion Config Options
  1059. ----------------------------
  1060. There is only one option available to configure a legacy minion for winrepo.
  1061. - ``win_repo_cachefile``
  1062. ``win_repo_cachefile``: (str)
  1063. The location on the Salt file server to obtain the winrepo database file. The
  1064. default is ``salt://win/repo/winrepo.p``
  1065. .. note::
  1066. If the location of the ``winrepo.p`` file is not in the default location on
  1067. the master, the :conf_minion:`win_repo_cachefile` setting will need to be
  1068. updated to reflect the proper location on each minion.
  1069. Legacy Quick Start
  1070. ==================
  1071. You can get up and running with winrepo pretty quickly just using the defaults.
  1072. Assuming no changes to the default configuration (ie, ``file_roots``) run the
  1073. following commands on the master:
  1074. .. code-block:: bash
  1075. salt-run winrepo.update_git_repos
  1076. salt-run winrepo.genrepo
  1077. salt * pkg.refresh_db
  1078. salt * pkg.install firefox
  1079. These commands clone the default winrepo from github, generate the metadata
  1080. file, push the metadata file down to the legacy minion, and install the latest
  1081. version of Firefox.
  1082. Legacy Initialization
  1083. =====================
  1084. Initializing the winrepo for a legacy minion is similar to that for a newer
  1085. minion. There is an added step in that the metadata file needs to be generated
  1086. on the master prior to refreshing the database on the minion.
  1087. Populate the Local Repository
  1088. -----------------------------
  1089. The SLS files used to install Windows packages are not distributed by default
  1090. with Salt. So, the first step is to clone the repo to the master. Use the
  1091. :mod:`winrepo.update_git_repos <salt.runners.winrepo.update_git_repos>`
  1092. runner initialize the repository in the location specified by ``winrepo_dir``
  1093. in the master config. This will pull the software definition files down from the
  1094. git repository.
  1095. .. code-block:: bash
  1096. salt-run winrepo.update_git_repos
  1097. Generate the Metadata File
  1098. --------------------------
  1099. The next step is to create the metadata file for the repo (``winrepo.p``).
  1100. The metadata file is generated on the master using the
  1101. :mod:`winrepo.genrepo <salt.runners.winrepo.genrepo>` runner.
  1102. .. code-block:: bash
  1103. salt-run winrepo.genrepo
  1104. .. note::
  1105. You only need to do this if you need to support legacy minions.
  1106. Update the Minion Database
  1107. --------------------------
  1108. Run :mod:`pkg.refresh_db <salt.modules.win_pkg.refresh_db>` on each of your
  1109. Windows minions to copy the metadata file down to the minion.
  1110. .. code-block:: bash
  1111. # From the master
  1112. salt -G 'os:windows' pkg.refresh_db
  1113. .. _2015-8-0-winrepo-changes:
  1114. Changes in Version 2015.8.0+
  1115. ============================
  1116. Git repository management for the Windows Software Repository changed in version
  1117. 2015.8.0, and several master/minion config parameters were renamed for
  1118. consistency.
  1119. For a complete list of the new winrepo config options, see
  1120. :ref:`here <winrepo-master-config-opts>` for master config options, and
  1121. :ref:`here <winrepo-minion-config-opts>` for configuration options for masterless Windows
  1122. minions.
  1123. pygit2_/GitPython_ Support
  1124. --------------------------
  1125. On the master, the
  1126. :mod:`winrepo.update_git_repos <salt.runners.winrepo.update_git_repos>`
  1127. runner was updated to use either pygit2_ or GitPython_ to checkout the git
  1128. repositories containing repo data. If pygit2_ or GitPython_ is installed,
  1129. existing winrepo git checkouts should be removed after upgrading to 2015.8.0.
  1130. Then they should be cloned again by running
  1131. :mod:`winrepo.update_git_repos <salt.runners.winrepo.update_git_repos>`.
  1132. If neither GitPython_ nor pygit2_ are installed, Salt will fall back to
  1133. pre-existing behavior for
  1134. :mod:`winrepo.update_git_repos <salt.runners.winrepo.update_git_repos>`, and a
  1135. warning will be logged in the master log.
  1136. .. note::
  1137. Standalone Windows minions do not support the new GitPython_/pygit2_
  1138. functionality, and will instead use the
  1139. :mod:`git.latest <salt.states.git.latest>` state to keep repositories
  1140. up-to-date. More information on how to use the Windows Software Repo on a
  1141. standalone minion can be found :ref:`here <standalone-winrepo>`.
  1142. Config Parameters Renamed
  1143. -------------------------
  1144. Many of the legacy winrepo configuration parameters changed in version 2015.8.0
  1145. to make them more consistent. Below are the parameters which changed for
  1146. version 2015.8.0:
  1147. Master Config
  1148. ======================== ================================
  1149. Old Name New Name
  1150. ======================== ================================
  1151. win_repo :conf_master:`winrepo_dir`
  1152. win_repo_mastercachefile No longer used on master
  1153. win_gitrepos :conf_master:`winrepo_remotes`
  1154. ======================== ================================
  1155. .. note::
  1156. The ``winrepo_dir_ng`` and ``winrepo_remotes_ng`` settings were introduced
  1157. in 2015.8.0 for working with the next generation repo.
  1158. See :ref:`here <winrepo-master-config-opts>` for detailed information on all
  1159. master config options for the Windows Repo.
  1160. Minion Config
  1161. ======================== ================================
  1162. Old Name New Name
  1163. ======================== ================================
  1164. win_repo :conf_minion:`winrepo_dir`
  1165. win_repo_cachefile :conf_minion:`winrepo_cachefile`
  1166. win_gitrepos :conf_minion:`winrepo_remotes`
  1167. ======================== ================================
  1168. .. note::
  1169. The ``winrepo_dir_ng`` and ``winrepo_remotes_ng`` settings were introduced
  1170. in 2015.8.0 for working with the next generation repo.
  1171. See :ref:`here <winrepo-minion-config-opts>` for detailed information on all
  1172. minion config options for the Windows Repo.
  1173. .. _wiki: https://wpkg.org/Category:Silent_Installers
  1174. .. _pygit2: https://github.com/libgit2/pygit2
  1175. .. _GitPython: https://github.com/gitpython-developers/GitPython