update to not auto-install PSCX

- will use built-in powershell method instead for .zip files
- added example for installing pscx as a pretask
This commit is contained in:
Phil 2015-06-18 16:15:15 -05:00
parent c6d5680967
commit 623a29cc0e
2 changed files with 21 additions and 48 deletions

View file

@ -1,7 +1,7 @@
#!powershell
# 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
# 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"
}
}
# Need PSCX
# Requires PSCX
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
$list = Get-Module -ListAvailable
# If not download it and install
If (-Not ($list -match "PSCX")) {
# Try install with chocolatey
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
Fail-Json "PowerShellCommunityExtensions PowerShell Module (PSCX) is required for non-'.zip' compressed archive types."
}
Else {
Set-Attr $result.win_zip "pscx_status" "present"
@ -124,18 +94,8 @@ Else {
# Import
Try {
If ($installed) {
Try {
Import-Module 'C:\Program Files (x86)\Powershell Community Extensions\pscx3\pscx\pscx.psd1'
}
Catch {
Import-Module PSCX
}
}
Else {
Import-Module PSCX
}
}
Catch {
Fail-Json $result "Error importing module PSCX"
}

View file

@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2014, Phil Schwartz <schwartzmx@gmail.com>
# (c) 2015, Phil Schwartz <schwartzmx@gmail.com>
#
# 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
timeout=600
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"
'''