update to not auto-install PSCX - will use built-in powershell method instead for .zip files - added example for installing pscx as a pretask

pull/18777/head
Phil 10 years ago committed by Matt Clay
parent 97744b2dc0
commit 8d9697e7fe

@ -1,7 +1,7 @@
#!powershell #!powershell
# This file is part of Ansible # This file is part of Ansible
# #
# Copyright 2014, Phil Schwartz <schwartzmx@gmail.com> # Copyright 2015, Phil Schwartz <schwartzmx@gmail.com>
# #
# Ansible is free software: you can redistribute it and/or modify # Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -80,43 +80,13 @@ If ($ext -eq ".zip" -And $recurse -eq $false) {
Fail-Json $result "Error unzipping $src to $dest" Fail-Json $result "Error unzipping $src to $dest"
} }
} }
# Need PSCX # Requires PSCX
Else { Else {
# Requires PSCX, will be installed if it isn't found
# Pscx-3.2.0.msi
$url = "http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=pscx&DownloadId=923562&FileTime=130585918034470000&Build=20959"
$msi = "C:\Pscx-3.2.0.msi"
# Check if PSCX is installed # Check if PSCX is installed
$list = Get-Module -ListAvailable $list = Get-Module -ListAvailable
# If not download it and install
If (-Not ($list -match "PSCX")) { If (-Not ($list -match "PSCX")) {
# Try install with chocolatey Fail-Json "PowerShellCommunityExtensions PowerShell Module (PSCX) is required for non-'.zip' compressed archive types."
Try {
cinst -force PSCX -y
$choco = $true
}
Catch {
$choco = $false
}
# install from downloaded msi if choco failed or is not present
If ($choco -eq $false) {
Try {
$client = New-Object System.Net.WebClient
$client.DownloadFile($url, $msi)
}
Catch {
Fail-Json $result "Error downloading PSCX from $url and saving as $dest"
}
Try {
Start-Process -FilePath msiexec.exe -ArgumentList "/i $msi /qb" -Verb Runas -PassThru -Wait | out-null
}
Catch {
Fail-Json $result "Error installing $msi"
}
}
Set-Attr $result.win_zip "pscx_status" "pscx was installed"
$installed = $true
} }
Else { Else {
Set-Attr $result.win_zip "pscx_status" "present" Set-Attr $result.win_zip "pscx_status" "present"
@ -124,17 +94,7 @@ Else {
# Import # Import
Try { Try {
If ($installed) { Import-Module PSCX
Try {
Import-Module 'C:\Program Files (x86)\Powershell Community Extensions\pscx3\pscx\pscx.psd1'
}
Catch {
Import-Module PSCX
}
}
Else {
Import-Module PSCX
}
} }
Catch { Catch {
Fail-Json $result "Error importing module PSCX" Fail-Json $result "Error importing module PSCX"

@ -1,7 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2014, Phil Schwartz <schwartzmx@gmail.com> # (c) 2015, Phil Schwartz <schwartzmx@gmail.com>
# #
# This file is part of Ansible # This file is part of Ansible
# #
@ -126,4 +126,17 @@ $ ansible -i hosts -m win_unzip -a "src=C:\\LibraryToUnzip.zip dest=C:\\Lib rm=t
delay=15 delay=15
timeout=600 timeout=600
state=started state=started
# Install PSCX to use for extracting a gz file
- name: Grab PSCX msi
win_get_url:
url: 'http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=pscx&DownloadId=923562&FileTime=130585918034470000&Build=20959'
dest: 'C:\\pscx.msi'
- name: Install PSCX
win_msi:
path: 'C:\\pscx.msi'
- name: Unzip gz log
win_unzip:
src: "C:\\Logs\\application-error-logs.gz"
dest: "C:\\ExtractedLogs\\application-error-logs"
''' '''

Loading…
Cancel
Save