ansible
6 years, 4 months ago
---
- name : Apply patch for windows 2016
#give host ip address
hosts: XXX
vars:
#give hostfix id which you want to upgrade in hostfix variable
hotfix: 'XXXX'
tasks:
- name: Check ping , only for test pourpose
win_ping:
- block:
- name: Check if {{ hotfix }} hotfix has been applied
raw: Get-Hotfix -Id "{{ hotfix }}" -computername XXXX
register: hotfix_status
failed_when: false
changed_when: false
- name: show output status
debug:
var: hotfix_status
- block:
- win_file:
path: "C:\\kbs\\archive"
state: directory
- win_get_url:
#get the url from windows patches update
url: "http://download.windowsupdate.com/c/msdownload/update/software/secu/2018/04/windows10.0-kb4093119-x64_553b6ac77ec6100784cdf1947b3fb83403aa5d1c.msu"
dest: "C:/kbs/windows10.0-kb4093119-x64_553b6ac77ec6100784cdf1947b3fb83403aa5d1c.msu"
force: no
- name: unpack the hotfix if needed
raw: 'expand -f:* "C:\kbs\windows10.0-kb4093119-x64_553b6ac77ec6100784cdf1947b3fb83403aa5d1c.msu" c:\kbs'
- name: use dism to install the cab containing the hotfix
raw: 'dism /online /add-package /norestart /PackagePath:"C:/kbs/Windows10.0-KB4093119-x64.cab"'
register: dism_output
changed_when: "true"
failed_when: "dism_output.rc != 0 and dism_output.rc != 3010 and dism_output.rc != 1641"
# Block execution
when: "hotfix_status.rc == 1"
0 Comments
Please Login to Comment Here