https://docs.saltstack.com/en/latest/topics/windows/windows-package-manager.html
可以看官网文档,本人英文差,翻译不好,谅解
在2015.8.0及更高版本中,Windows Software Repository缓存是在Salt Minion上编译的
SaltStack Windows软件资源库提供了一个软件包管理器和软件资源库,类似于Linux上的yum和apt提供的资源库。该存储库可以使用远程Windows系统上的安装程序来安装软件。
In many senses, the operation is similar to that of the other package managers salt is aware of:
the pkg.installed
and similar states work on Windows.
the pkg.install
and similar module functions work on Windows.
和yum的区别
1,存储库元数据(SLS文件)通过salt或git托管。
2,软件包可以从salt仓库,git仓库或http(s)或ftp URL下载。
3,包之间的依赖关系需要手动管理。
使用之前的要求是:GitPython 0.3或更高版本,或者在Salt mast上安装libgit 0.20.0或更高版本的pygit2 0.20.3。Windows软件包定义是使用Git下载和更新的。
默认情况下salt不会进行分发用于安装Windows软件包的SLS文件,需要运行以下命令以初始化您的Salt主机上的存储库:
salt-run winrepo.update_git_repos
SYNC REPO TO WINDOWS MINIONS
Run pkg.refresh_db
on each of your Windows minions to synchronize the package repository.
salt -G'os : windows'pkg.refresh_db
接下来就可以安装windows软件
显示已安装的软件包 salt -G'os : windows'pkg.list_pkgs
您可以使用Salt pkg模块查询软件包的可用版本 salt winminion pkg.list_available firefox
安装最新版本的Firefox salt winminion pkg.install'firefox '
卸载WINDOWS软件
使用pkg模块卸载软件
salt winminion pkg.remove firefox salt winminion pkg.purge firefox
Note
pkg.purge
just executes pkg.remove
on Windows. At some point in the future pkg.purge
may direct the installer to remove all configs and settings for software packages that support that option
存储库位置
Salt维护SLS文件的存储库来安装大量的Windows软件包:
- 2015.8.0及以后的版本:https://github.com/saltstack/salt-winrepo-ng
- 早期版本:https://github.com/saltstack/salt-winrepo
默认情况下,这些存储库被镜像到/srv/salt/win/repo-ng
和/srv/salt/win/repo
。
通过设置winrepo_dir_ng
和winrepo_dir
选项,可以在主配置文件中更改此位置 。
MAINTAINING WINDOWS REPO DEFINITIONS IN GIT REPOSITORIES
可以托管在一个或多个Git存储库中,默认存储库由SaltStack托管在GitHub上。这些包括各种开源软件项目的软件定义文件。这些软件定义文件是.sls
文件。有两个默认的存储库:salt-winrepo
和salt-winrepo-ng
。salt-winrepo
包含旧版本(旧版本2015.8.0)的软件定义文件。salt-winrepo-ng
是为更新的奴才(2015.8.0和更新)。
每个软件定义文件都包含salt在安装该软件所需的所有信息,包括安装程序文件的HTTP或FTP位置,用于静默安装的所需命令等, Anyone is welcome to send a pull request to this repo to add new package definitions. The repos can be browsed here: salt-winrepo salt-winrepo-ng
Note
The newer software definition files are run through the salt's parser which allows for the use of jinja.
通过修改或扩展winrepo_remotes
和 winrepo_remotes_ng
选项,配置主服务器可以搜索包定义的那些git存储库。
Important
winrepo_remotes
was called win_gitrepos
in Salt versions earlier than 2015.8.0
软件包定义通过运行winrepo.update_git_repos
runner 从online存储库中取出 。该命令在主服务器上运行:
salt-run winrepo.update_git_repos
This will pull down the software definition files for older minions (salt-winrepo
) and new minions (salt-winrepo-ng
). They are stored in the file_roots
under win/repo/salt-winrepo
andwin/repo-ng/salt-winrepo-ng
respectively.
重要
如果您有自定义的软件定义文件,而这些软件定义文件不是在版本库中维护的,那么应该将这些文件存储在win/repo
较旧的版本和 win/repo-ng
较新版本的版本中。这样做的原因是,内容win/repo/salt-winrepo
和win/repo-ng/salt-winrepo-ng
在每次运行时清除winrepo.update_git_repos
。
此外,当您运行winrepo.genrepo
和pkg.refresh_db
下的全部内容win/repo
和win/repo-ng
,包括所有子目录,用于创建msgpack文件
The next step (if you have older minions) is to create the msgpack file for the repo (winrepo.p
). This is done by running the winrepo.genrepo
runner. This is also run on the master:
salt-run winrepo.genrepo
Note
If you have only 2015.8.0 and newer minions, you no longer need to run salt-run winrepo.genrepo
on the master.
最后,您需要通过运行该pkg.refresh_db
命令来刷新minion数据库 。这也在master上运行:
salt '*' pkg.refresh_db
On older minions (older than 2015.8.0) this will copy the winrepo.p file down to the minion. On newer minions (2015.8.0 and newer) this will copy all the software definition files (.sls) down to the minion and then create the msgpack file (winrepo.p
) locally. The reason this is done locally is because the jinja needs to be parsed using the minion's grains.
每次在master服务器上修改软件定义文件时,无论是通过运行,修改现有文件,还是通过创建自己的文件,都需要刷新minion上的数据库, For older minions, that means running salt-run winrepo.genrepo
and thensalt '*' pkg.refresh_db
. For newer minions (2015.8.0 and newer) it is just salt '*' pkg.refresh_db
.
注意
如果这个winrepo.genrepo
或者pkg.refresh_db
失败了,那么在一个软件定义文件中,这可能是一个jinja 问题。这将导致操作停止。您需要修复语法,才能成功创建msgpack文件。
要禁用其中一个repo,请将其设置[]
为主配置中的空白列表。例如,要禁用winrepo_remotes
在主配置文件中设置以下内容:winrepo_remotes:[]
创建一个包定义SLS文件
包定义文件是一个yaml文件,其中包含使用salt安装一个软件所需的所有信息。它定义了有关软件包的信息,包括版本,全名,安装程序和卸载程序所需的标志,是否使用Windows任务计划程序安装软件包,以及如何查找安装软件包等。
看看Firefox的这个例子:
firefox: '17.0.1': installer: 'salt://win/repo/firefox/English/Firefox Setup 17.0.1.exe' full_name: Mozilla Firefox 17.0.1 (x86 en-US) locale: en_US reboot: False install_flags: '-ms' uninstaller: '%ProgramFiles(x86)%/Mozilla Firefox/uninstall/helper.exe' uninstall_flags: '/S' '16.0.2': installer: 'salt://win/repo/firefox/English/Firefox Setup 16.0.2.exe' full_name: Mozilla Firefox 16.0.2 (x86 en-US) locale: en_US reboot: False install_flags: '-ms' uninstaller: '%ProgramFiles(x86)%/Mozilla Firefox/uninstall/helper.exe' uninstall_flags: '/S' '15.0.1': installer: 'salt://win/repo/firefox/English/Firefox Setup 15.0.1.exe' full_name: Mozilla Firefox 15.0.1 (x86 en-US) locale: en_US reboot: False install_flags: '-ms' uninstaller: '%ProgramFiles(x86)%/Mozilla Firefox/uninstall/helper.exe' uninstall_flags: '/S'
每个软件定义文件都以该软件的软件包名称开头。如上例所示firefox
。下一行缩进两个空格,并包含要定义的版本。如上例所示,软件定义文件可以为同一个软件定义多个版本。该版本后面的行缩进了两个空格,并包含安装该软件包所需的全部信息。
警告
软件包名称和full_name
软件存储库中的所有其他软件包必须是唯一的。
版本行是要安装的软件包的版本。当您需要安装某个软件的特定版本时使用它。
警告
版本必须用引号括起来,否则yaml解析器会删除尾随的零。
注意
有以前版本不可用的独特情况。以Google Chrome为例。只有一个网址提供了Google Chrome的独立安装。(https://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi)当新版本发布时,网址只是指向新版本。要处理这些情况,请将版本设置为最新版本。Salt会在URL上安装Chrome版本并报告该版本。这是一个例子:
chrome:
latest:
full_name: 'Google Chrome'
installer: 'https://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi' install_flags: '/qn /norestart' uninstaller: 'https://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi' uninstall_flags: '/qn /norestart' msiexec: True locale: en_US reboot: False
参数str full_name: | |
---|---|
软件的全名,如控制面板中的“程序和功能”所示。您也可以通过手动安装软件包然后运行pkg.list_pkgs来获取此信息 。以下是来自pkg.list_pkgs 以下输出的示例: |
salt 'test-2008' pkg.list_pkgs test-2008 ---------- 7-Zip 9.20 (x64 edition): 9.20.00.0 Microsoft .NET Framework 4 Client Profile: 4.0.30319,4.0.30319 Microsoft .NET Framework 4 Extended: 4.0.30319,4.0.30319 Microsoft Visual C++ 2008 Redistributable - x64 9.0.21022: 9.0.21022 Mozilla Firefox 17.0.1 (x86 en-US): 17.0.1 Mozilla Maintenance Service: 17.0.1 NSClient++ (x64): 0.3.8.76 Notepad++: 6.4.2 Salt Minion 0.16.0: 0.16.0
注意Firefox的全名:Mozilla Firefox 17.0.0(x86 en-US)。这正是full_name
软件定义文件中的参数。
参数str安装程序: | |
---|---|
安装包所使用的EXE或MSI的路径。。这可以是路径或URL。如果它是一个URL或一个salt路径(salt://),那么这个包将被本地缓存,然后执行。如果它是磁盘或文件共享上的文件的路径,它将直接执行。 | |
参数str install_flags: | |
任何需要传递给安装程序的标志使其执行无提示安装。这些通常可以通过添加/? 或/h 从命令行运行安装程序来找到。在WPKG项目的wiki上可以找到找到这些静默安装标志的很好的资源: |
如果安装程序正在等待用户输入,salt将不会返回,因此这些是非常重要的。
参数str卸载程序: | |
---|---|
用于卸载该软件的程序的路径。这可以是用于安装软件的相同exe或msi的路径。它也可以是一个GUID。您可以在注册表中找到以下键值:
|
|
参数str uninstall_flags: | |
任何需要传递给卸载程序的标志,使其执行无提示卸载。这些通常可以通过添加 |
如果卸载程序正在等待用户输入,salt将不会返回,因此这些是非常重要的。
以下是一些安装程序和卸载程序设置的示例:
7zip的: '9.20.00.0' : 安装程序: salt://win/repo/7zip/7z920-x64.msi FULL_NAME : 7-ZIP 9.20(64版) 重启: 假 install_flags : '/ QN / norestart更新日志文件' MSIEXEC :真卸载:'{23170F69-40C1-2702-0920-000001000000}' uninstall_flags :'/ qn / norestart'
或者,uninstaller
也可以简单地重复msi文件的URL。
7zip的: '9.20.00.0' : 安装程序: salt://win/repo/7zip/7z920-x64.msi FULL_NAME : 7-ZIP 9.20(64版) 重启: 假 install_flags : '/ QN / norestart更新日志文件' MSIEXEC :真卸载:salt://win/repo/7zip/7z920-x64.msi uninstall_flags :'/ qn / norestart'
param msiexec: | 这告诉salt用来安装软件包并卸载。这是为.msi安装。可能的选项有:True,False或路径到您的系统上的msiexec
|
---|---|
参数: | 这选择 |
param bool allusers: | |
此参数特定于.msi安装。它告诉msiexec为所有用户安装软件。默认值是True。 |
|
param bool cache_dir: | |
如果安装程序URL以salt://开头,则安装程序所在的整个目录将被递归缓存。这对依赖于同一目录中的其他文件进行安装的安装程序非常有用。 |
|
参数str cache_file: | |
当安装程序URL以salt://开头时,表示单个文件要复制下来以便与安装程序一起使用。复制到与安装程序相同的位置。使用此过 |
以下是具有相关文件的软件包的示例:
sqlexpress: '12.0.2000.8': installer: 'salt://win/repo/sqlexpress/setup.exe' full_name: Microsoft SQL Server 2014 Setup (English) reboot: False install_flags: '/ACTION=install /IACCEPTSQLSERVERLICENSETERMS /Q' cache_dir: True
param bool use_scheduler: | |
---|---|
如果为true,则Windows将使用任务计划程序来运行安装。这对运行salt安装本身很有用,因为安装过程会杀死任何正在运行的salt实例。 | |
参数str source_hash: | |
这告诉salt比较安装程序的哈希总和 |
到执行前提供的哈希总和。该值可以格式化为 hash_algorithm=hash_sum
,也可以是包含散列和的文件的URI。有关支持的算法列表,请参阅hashlib文档。
这是一个source_hash用法的例子:
messageanalyzer : '4.0.7551.0' : FULL_NAME : '微软消息分析器' 安装程序:'salt://win/repo/messageanalyzer/MessageAnalyzer64.msi' install_flags :'/安静/ norestart更新日志文件' 卸载:“{1CC02C23-8FCD-487E- 860C-311EC0A0C933}” uninstall_flags :'/安静/ norestart更新日志文件' MSIEXEC :真source_hash :'SHA1 = 62875ff451f13b10a8ff988f2943e76a4735d3d4'
param bool reboot: | |
---|---|
未实现 | |
参数str local: | |
未实现 |
在独立WINDOWS MINION上管理WINDOWS软件
Windows Package Repository在独立环境中的功能类似,在配置上有一些差异。
为了替换Salt master使用的winrepo runner,存在一个执行模块来为独立的minion提供相同的功能。。这些函数的名称与runner中的相同,并以相同的方式使用。唯一的区别是用来代替:execution module
salt-call
salt-run
salt-call winrepo.update_git_repos
salt-call winrepo.genrepo
salt-call pkg.refresh_db
执行完上述命令之后,独立系统上的存储库就可以使用了。
存储库SLS文件的自定义位置
如果file_roots
在minion配置中没有被修改,那么不需要在minion配置中添加额外的配置。执行模块的winrepo.genrepo
函数winrepo
默认会查找由winrepo_cachefile
内部 指定的文件名C:\salt\srv\salt\win\repo
。
如果file_roots
参数已被修改,则 winrepo_dir
必须将其修改为适当的相对路径内的路径。例如,如果base
在环境 file_roots
分D:\foo
,并且 winrepo_source_dir
是salt://win/repo
,则 winrepo_dir
必须设置为D:\foo\win\repo
确保 winrepo.genrepo
放求CacheFile到正确的位置。
MINIONS 2015.8.0及更高版本的配置选项
该winrepo_source_dir
配置参数(默认 salt://win/repo
)控制在pkg.refresh_db
查找中求CacheFile(默认: winrepo.p
)。这意味着winrepo缓存文件的默认位置是salt://win/repo/winrepo.p
。双方winrepo_source_dir
并winrepo_cachefile
可以调整,以匹配salt文件服务器这个文件的实际位置。
在2015.8.0之前配置MINIONS的配置选项
如果连接到master,minion将默认查找winrepo cachefile(由该文件生成的)at 。如果缓存文件在salt文件服务器上位于不同的路径上,则 需要更新以反映正确的位置。winrepo.genrepo runner
salt://win/repo/winrepo.p
win_repo_cachefile
版本2015.8.0中的更改
Windows软件存储库的Git存储库管理在版本2015.8.0中已更改,并且已重命名了多个主/从配置参数,以使其命名更加一致。
有关winrepo配置选项的列表,请参阅此处以了解主配置选项,以及此处的无主Windows 副镜的配置选项。
在master上,winrepo.update_git_repos
跑步者已经更新,使用 pygit2或者GitPython来签出包含repo数据的git版本库。如果 安装了pygit2或GitPython,升级到2015.8.0之后应该删除现有的winrepo git checkout,以允许通过运行再次检出它们winrepo.update_git_repos
。
如果既没有安装GitPython也没有安装pygit2,那么Salt将回退到预先存在的行为winrepo.update_git_repos
,并在主日志中记录警告。
注意
独立的Windows小工具不支持新的GitPython / pygit2 功能,而是使用git.latest
状态来使存储库保持最新状态。在这里可以找到更多关于如何在单机版中使用Windows软件回收的信息。
配置参数重命名
许多传统winrepo配置参数在版本2015.8.0中已更改,以使命名更加一致。旧的参数名称仍然有效,但会记录一个警告,指出旧名称已被弃用。
以下是2015.8.0版本中已更改的参数:
主配置
老名字 | 新名字 |
---|---|
win_repo | winrepo_dir |
win_repo_mastercachefile | winrepo_cachefile |
win_gitrepos | winrepo_remotes |
注意
winrepo_cachefile
在2015.8.0及更新的版本中不再使用,并且2015.8.0及更新版本的版本winrepo_dir
将取代winrepo_dir_ng
该版本。
请参阅此处了解有关Windows回购的所有主配置选项的详细信息。
master配置
老名字 | 新名字 |
---|---|
win_repo | winrepo_dir |
win_repo_cachefile | winrepo_cachefile |
win_gitrepos | winrepo_remotes |
请参阅此处了解有关Windows回购的所有小型配置选项的详细信息。
PYGIT2 / GITPYTHON支持维护GIT REPOS
的winrepo.update_git_repos
转轮(以及对应的用于独立爪牙)现在利用所使用的相同的底层代码的GIT中文件服务器后端和维持和更新git代码库的本地克隆。如果安装了pygit2(0.20.3和更高版本)或GitPython(0.3.0或更高版本)的兼容版本,则Salt将使用它而不是旧方法(调用该 状态)。remote execution function
Git External Pillar
git.latest
注意
如果安装了pygit2和GitPython的兼容版本,那么Salt会偏好pygit2,使用winrepo_provider
配置参数覆盖此行为 :
winrepo_provider : gitpython
将(在上面讨论管理Windows软件上独立的Windows爪牙部分)还没有正式支持新 pygit2 / GitPython的功能,但如果任pygit2或GitPython安装到salt的捆绑Python的那么它应该工作。但是,这个时候应该被认为是实验性的。winrepo execution module
为了最大限度地减少潜在的问题,最好的办法是将主版本升级到2015.8.0或更高版本时,删除旧版(2015.8.0之前版本)winrepo代码签出的winrepo git版本库,然后运行 winrepo.update_git_repos
克隆它们主人开始了。
额外的附加功能包括能够访问认证的git存储库(注意: 仅适用于pygit2),并设置每个远程配置设置。这方面的例子如下:
winrepo_remotes : - https://github.com/saltstack/salt-winrepo.git - git@github.com:myuser / myrepo.git : - pubkey : /path/to/key.pub - privkey : / path / to /密钥 - 密码: myaw3s0m3pa $$ phr4 $ 3 - https://github.com/myuser/privaterepo.git : - user : mygithubuser - 密码: CorrectHorseBatteryStaple
注意
每个远程配置设置的工作方式与它们在gitfs中的设置相同,全局参数被其远程对应设备覆盖(例如,设置winrepo_passphrase
将为winrepo设置一个全局口令,适用于所有基于SSH的远程,除非由passphrase
每个远程参数覆盖)。
请参阅这里了解更多有关每个远程配置如何在gitfs中工作的更深入的解释,相同的原则适用于winrepo。
Salt如何使用pygit2 / GitPython管理git repos还有其他一些变化 。首先,一个clean
参数已经被添加到winrepo.update_git_repos
跑步者,该参数(如果设置为True
)将告诉跑步者在winrepo_dir
没有明确配置的目录下处理目录。这样可以防止在从配置文件中删除回购站时手动删除这些目录。要清理这些旧的目录clean=True
,就像这样传递 :
salt运行winrepo.update_git_repos 干净=真
但是,如果正在使用的Git和非混帐的Windows回购定义文件的混合,那么这应该不被使用,因为它会删除包含非git的定义的目录。
另一个主要变化是现在检测到回购商之间的冲突,winrepo.update_git_repos
如果检测到任何商品,运动员将不会进行。考虑以下配置:
winrepo_remotes : - https://foo.com/bar/baz.git - https://mydomain.tld/baz.git - https://github.com/foobar/baz
该winrepo.update_git_repos
选手将拒绝此更新回购,因为这些回购的所有三个将被检出到同一个目录。要解决此问题,name
可以使用调用的每个远程参数来解决这些冲突:
winrepo_remotes : - https://foo.com/bar/baz.git - https://mydomain.tld/baz.git : - 名称: baz_junior - https://github.com/foobar/baz : - 名称: baz_the_third
故障排除
不正确的名称/版本
如果包似乎安装正确,但salt报告失败,那么很可能你有一个版本或full_name
不匹配。
检查full_name
软件包使用的确切版本和版本。使用 pkg.list_pkgs
检查名称和版本完全匹配安装的是什么。
更改SLS文件没有被拿起
确保你已经(重新)生成了仓库缓存文件(对于旧版本的小版本),然后更新了相关版本的仓库缓存:
salt运行winrepo.genrepo
saltwinminion pkg.refresh_db
在WINDOWS 2003下的软件包管理
在Windows Server 2003上,您需要安装可选的Windows组件“wmi windows安装程序提供程序”以具有已安装软件包的完整列表。如果你没有这个,salt-minion不能报告一些安装的软件。
如何报告成功和失败
Windows包管理器的安装状态/模块功能大致如下所示:
- 执行
pkg.list_pkgs
并存储结果 - 检查是否需要采取任何行动。(即比较所需的软件包和版本与
pkg.list_pkgs
结果) - 如果是这样,请运行安装程序命令。
- 执行
pkg.list_pkgs
并与安装前存储的结果进行比较。 - 成功/失败/变化将根据原始和最终
pkg.list_pkgs
结果之间的差异进行报告。
如果在使用软件包管理器时遇到任何问题,可能是由于您的sls文件中的数据与前后pkg.list_pkgs
结果之间的差异不匹配 。