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命令解析如下:

wKioL1lnWqjB7CSvAABaKdcUlio148.png-wh_50

變更到ansible,我們需要調用win_shell命令

$ ansible win_group -m win_shell -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安裝成功的日誌記錄,和已經安裝完成補丁列表的截圖

wKioL1lnWsrAvXsPAAA8Rn5na18790.png-wh_50

windows補丁安裝列表:

wKiom1lnWsrAy_KgAAAeD39WXJI478.png-wh_50

後續有個設想,把這個操作全程作爲自動化,看看自己需要多長時間才能完成。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章