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
結果之間的差異不匹配 。