標籤:自動化營運 ansible windows自動化營運
前一陣因為windows SMB協議漏洞,手動給windows打補丁,累覺不愛。
研究後找出簡單方法,使用ansible進行批量化操作,避免人工的繁雜。
windows補丁下載網站
https://www.catalog.update.microsoft.com/Search.aspx
下載一個KB4025337,得到連結:
$ wget http://download.windowsupdate.com/c/msdownload/update/software/secu/2017/07/windows6.1-kb4025337-x64_c013b7fcf3486a0f71c4f58fc361bfdb715c4e94.msu
使用ansible命令將這個補丁複製到C盤
$ ansible win_group -m win_copy -a "src=/ms補丁/windows6.1-kb4025337-x64.msu dest=c:\ "
win_group是定義在hosts中的主機群組
cmd中執行的命令如下:
wusa c:\windows6.1-kb4025337-x64_.msu /quiet /norestart /log
wusa命令解析如下:
650) this.width=650;" src="https://s4.51cto.com/wyfs02/M01/9B/D1/wKioL1lnWqjB7CSvAABaKdcUlio148.png-wh_500x0-wm_3-wmp_4-s_1161271256.png" title="wusa.png" alt="wKioL1lnWqjB7CSvAABaKdcUlio148.png-wh_50" />
變更到ansible,我們需要調用win_shell命令
$ ansible win_group -m win_copy -a "wusa c:\windows6.1-kb4025337-x64.msu /quiet /norestart /log"
至於為何不使用win_command模組的原因如下
The given command will be executed on all selected nodes. It will not be processed through the shell, so variables like $env:HOME and operations like "<", ">", "|", and ";" will not work (use the win_shell module if you need these features).
最後附上windows安裝成功的日誌記錄,和已經安裝完成補丁列表的
650) this.width=650;" src="https://s2.51cto.com/wyfs02/M02/9B/D1/wKioL1lnWsrAvXsPAAA8Rn5na18790.png-wh_500x0-wm_3-wmp_4-s_2604649701.png" style="float:none;" title="sj.png" alt="wKioL1lnWsrAvXsPAAA8Rn5na18790.png-wh_50" />
windows補丁安裝列表:
650) this.width=650;" src="https://s2.51cto.com/wyfs02/M01/9B/D1/wKiom1lnWsrAy_KgAAAeD39WXJI478.png-wh_500x0-wm_3-wmp_4-s_4162733747.png" style="float:none;" title="jl.png" alt="wKiom1lnWsrAy_KgAAAeD39WXJI478.png-wh_50" />
後續有個設想,把這個操作全程作為自動化,看看自己需要多長時間才能完成。
本文出自 “M層” 部落格,轉載請與作者聯絡!
ansible控制windows主機群批量打補丁