removes restart functionality, and added creates param for idempotency

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

@ -26,6 +26,13 @@ $result = New-Object psobject @{
changed = $false changed = $false
} }
If ($params.creates) {
If (Test-Path $params.creates) {
Exit-Json $result "The 'creates' file or directory already exists."
}
}
If ($params.src) { If ($params.src) {
$src = $params.src.toString() $src = $params.src.toString()
@ -86,7 +93,7 @@ Else {
$list = Get-Module -ListAvailable $list = Get-Module -ListAvailable
If (-Not ($list -match "PSCX")) { 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 { Else {
Set-Attr $result.win_unzip "pscx_status" "present" Set-Attr $result.win_unzip "pscx_status" "present"
@ -122,10 +129,10 @@ Else {
} }
Catch { Catch {
If ($recurse) { If ($recurse) {
Fail-Json "Error recursively expanding $src to $dest" Fail-Json $result "Error recursively expanding $src to $dest"
} }
Else { 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" 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" # 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 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 # This catches that possible error, before assigning the JSON $result

@ -63,16 +63,11 @@ options:
- yes - yes
- no - no
aliases: [] aliases: []
restart: creates:
description: 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) - If this file or directory exists the specified src will not be extracted.
choices: required: no
- true default: null
- false
- yes
- no
required: false
default: false
aliases: [] aliases: []
author: Phil Schwartz 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: win_unzip:
src: "C:\Users\Phil\Logs.bz2" src: "C:\Users\Phil\Logs.bz2"
dest: "C:\Users\Phil\OldLogs" 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. # 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 recurse: yes
rm: true 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 # Install PSCX to use for extracting a gz file
- name: Grab PSCX msi - name: Grab PSCX msi
win_get_url: win_get_url:

Loading…
Cancel
Save