removes restart functionality, and added creates param for idempotency

reviewable/pr18780/r1
Phil 10 years ago
parent 92744ef558
commit 03ce40a62e

@ -26,6 +26,13 @@ $result = New-Object psobject @{
changed = $false
}
If ($params.creates) {
If (Test-Path $params.creates) {
Exit-Json $result "The 'creates' file or directory already exists."
}
}
If ($params.src) {
$src = $params.src.toString()
@ -86,7 +93,7 @@ Else {
$list = Get-Module -ListAvailable
If (-Not ($list -match "PSCX")) {
Fail-Json "PowerShellCommunityExtensions PowerShell Module (PSCX) is required for non-'.zip' compressed archive types."
Fail-Json $result "PowerShellCommunityExtensions PowerShell Module (PSCX) is required for non-'.zip' compressed archive types."
}
Else {
Set-Attr $result.win_unzip "pscx_status" "present"
@ -122,10 +129,10 @@ Else {
}
Catch {
If ($recurse) {
Fail-Json "Error recursively expanding $src to $dest"
Fail-Json $result "Error recursively expanding $src to $dest"
}
Else {
Fail-Json "Error expanding $src to $dest"
Fail-Json $result "Error expanding $src to $dest"
}
}
}
@ -135,11 +142,6 @@ If ($rm -eq $true){
Set-Attr $result.win_unzip "rm" "true"
}
If ($params.restart -eq "true" -Or $params.restart -eq "yes") {
Restart-Computer -Force
Set-Attr $result.win_unzip "restart" "true"
}
# Fixes a fail error message (when the task actually succeeds) for a "Convert-ToJson: The converted JSON string is in bad format"
# This happens when JSON is parsing a string that ends with a "\", which is possible when specifying a directory to download to.
# This catches that possible error, before assigning the JSON $result

@ -63,16 +63,11 @@ options:
- yes
- no
aliases: []
restart:
creates:
description:
- Restarts the computer after unzip, can be useful for hotfixes such as http://support.microsoft.com/kb/2842230 (Restarts will have to be accounted for with wait_for module)
choices:
- true
- false
- yes
- no
required: false
default: false
- If this file or directory exists the specified src will not be extracted.
required: no
default: null
aliases: []
author: Phil Schwartz
'''
@ -88,6 +83,7 @@ $ ansible -i hosts -m win_unzip -a "src=C:\\LibraryToUnzip.zip dest=C:\\Lib rm=t
win_unzip:
src: "C:\Users\Phil\Logs.bz2"
dest: "C:\Users\Phil\OldLogs"
creates: "C:\Users\Phil\OldLogs"
# This playbook example unzips a .zip file and recursively decompresses the contained .gz files and removes all unneeded compressed files after completion.
---
@ -102,31 +98,6 @@ $ ansible -i hosts -m win_unzip -a "src=C:\\LibraryToUnzip.zip dest=C:\\Lib rm=t
recurse: yes
rm: true
# Install hotfix (self-extracting .exe)
---
- name: Install WinRM PowerShell Hotfix for Windows Server 2008 SP1
hosts: all
gather_facts: false
tasks:
- name: Grab Hotfix from URL
win_get_url:
url: 'http://hotfixv4.microsoft.com/Windows%207/Windows%20Server2008%20R2%20SP1/sp2/Fix467402/7600/free/463984_intl_x64_zip.exe'
dest: 'C:\\463984_intl_x64_zip.exe'
- name: Unzip hotfix
win_unzip:
src: "C:\\463984_intl_x64_zip.exe"
dest: "C:\\Hotfix"
recurse: true
restart: true
- name: Wait for server reboot...
local_action:
module: wait_for
host={{ inventory_hostname }}
port={{ansible_ssh_port|default(5986)}}
delay=15
timeout=600
state=started
# Install PSCX to use for extracting a gz file
- name: Grab PSCX msi
win_get_url:

Loading…
Cancel
Save