summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimFicarra <JimFicarra@users.noreply.github.com>2017-01-26 20:56:24 -0500
committerMatt Davis <nitzmahone@users.noreply.github.com>2017-01-26 17:56:24 -0800
commitd2094cd611e861c0ed5bfd2a3a4bdd54e03b4f78 (patch)
tree3a3965d0d2a0850cc7389935cebbdb8e01e39bd2
parent2a27176d7c5e7a9216b569a24579a214aa2a2cee (diff)
downloadansible-d2094cd611e861c0ed5bfd2a3a4bdd54e03b4f78.tar.gz
win_feature fix issue #20433 - source param not found on win2k8 (#20435)
-rw-r--r--lib/ansible/modules/windows/win_feature.ps190
-rw-r--r--lib/ansible/modules/windows/win_feature.py8
2 files changed, 55 insertions, 43 deletions
diff --git a/lib/ansible/modules/windows/win_feature.ps1 b/lib/ansible/modules/windows/win_feature.ps1
index 339b79b9d7..8f1510ca0f 100644
--- a/lib/ansible/modules/windows/win_feature.ps1
+++ b/lib/ansible/modules/windows/win_feature.ps1
@@ -42,15 +42,34 @@ $includesubfeatures = Get-Attr $params "include_sub_features" $false | ConvertTo
$includemanagementtools = Get-Attr $params "include_management_tools" $false | ConvertTo-Bool
$source = Get-Attr $params "source" $false
-If ($state -eq "present") {
- if ($source)
- {
- if (!(test-path $source))
- {
- Fail-Json $result "Failed to find source path $source"
- }
+# Determine which cmdlets we need to work with. Then we can set options appropriate for the cmdlet
+$installWF= $false
+$addWF = $false
+
+try {
+ # We can infer uninstall/remove if install/add cmdlets exist
+ if (Get-Command "Install-WindowsFeature" -ErrorAction SilentlyContinue) {
+ $addCmdlet = "Install-WindowsFeature"
+ $removeCmdlet = "Uninstall-WindowsFeature"
+ $installWF = $true
+ }
+ elseif (Get-Command "Add-WindowsFeature" -ErrorAction SilentlyContinue) {
+ $addCmdlet = "Add-WindowsFeature"
+ $removeCmdlet = "Remove-WindowsFeature"
+ $addWF = $true
+ }
+ else {
+ throw [System.Exception] "Not supported on this version of Windows"
}
+}
+catch {
+ Fail-Json $result $_.Exception.Message
+}
+
+
+If ($state -eq "present") {
+ # Base params to cover both Add/Install-WindowsFeature
$InstallParams = @{
"Name"=$name;
"Restart"=$Restart;
@@ -58,48 +77,39 @@ If ($state -eq "present") {
"ErrorAction"="SilentlyContinue"
}
- if ($IncludeManagementTools -eq $true)
- {
- $InstallParams.add("IncludeManagementTools",$includemanagementtools)
- }
-
- if ($source)
- {
- $InstallParams.add("Source",$source)
- }
-
-
-
- try {
- If (Get-Command "Install-WindowsFeature" -ErrorAction SilentlyContinue) {
- $featureresult = Install-WindowsFeature @InstallParams
- }
- ElseIf (Get-Command "Add-WindowsFeature" -ErrorAction SilentlyContinue) {
- if ($IncludeManagementTools)
- {
- $InstallParams.Remove("IncludeManagementTools")
+ # IncludeManagementTools and source are options only for Install-WindowsFeature
+ if ($installWF) {
+
+ if ($source) {
+ if (!(test-path $source)) {
+ Fail-Json $result "Failed to find source path $source"
}
- $featureresult = Add-WindowsFeature @InstallParams
+
+ $InstallParams.add("Source",$source)
}
- Else {
- Fail-Json $result "Not supported on this version of Windows"
+
+ if ($IncludeManagementTools) {
+ $InstallParams.add("IncludeManagementTools",$includemanagementtools)
}
}
+
+ try {
+ $featureresult = Invoke-Expression "$addCmdlet @InstallParams"
+ }
catch {
Fail-Json $result $_.Exception.Message
}
}
ElseIf ($state -eq "absent") {
- try {
- If (Get-Command "Uninstall-WindowsFeature" -ErrorAction SilentlyContinue) {
- $featureresult = Uninstall-WindowsFeature -Name $name -Restart:$restart -ErrorAction SilentlyContinue
- }
- ElseIf (Get-Command "Remove-WindowsFeature" -ErrorAction SilentlyContinue) {
- $featureresult = Remove-WindowsFeature -Name $name -Restart:$restart -ErrorAction SilentlyContinue
- }
- Else {
- Fail-Json $result "Not supported on this version of Windows"
- }
+
+ $UninstallParams = @{
+ "Name"=$name;
+ "Restart"=$Restart;
+ "ErrorAction"="SilentlyContinue"
+ }
+
+ try {
+ $featureresult = Invoke-Expression "$removeCmdlet @UninstallParams"
}
catch {
Fail-Json $result $_.Exception.Message
diff --git a/lib/ansible/modules/windows/win_feature.py b/lib/ansible/modules/windows/win_feature.py
index 89c20ac88c..de6009b155 100644
--- a/lib/ansible/modules/windows/win_feature.py
+++ b/lib/ansible/modules/windows/win_feature.py
@@ -31,7 +31,7 @@ module: win_feature
version_added: "1.7"
short_description: Installs and uninstalls Windows Features on Windows Server
description:
- - Installs or uninstalls Windows Roles or Features on Windows Server. This module uses the Add/Remove-WindowsFeature Cmdlets, which is not available on client os machines.
+ - Installs or uninstalls Windows Roles or Features on Windows Server. This module uses the Add/Remove-WindowsFeature Cmdlets on Windows 2008 and Install/Uninstall-WindowsFeature Cmdlets on Windows 2012, which are not available on client os machines.
options:
name:
description:
@@ -64,7 +64,8 @@ options:
required: false
include_management_tools:
description:
- - Adds the corresponding management tools to the specified feature
+ - Adds the corresponding management tools to the specified feature.
+ - Not supported in Windows 2008. If present when using Windows 2008 this option will be ignored.
choices:
- yes
- no
@@ -72,7 +73,8 @@ options:
required: false
source:
description:
- - Specify a source to install the feature from
+ - Specify a source to install the feature from.
+ - Not supported in Windows 2008. If present when using Windows 2008 this option will be ignored.
required: false
choices: [ ' {driveletter}:\sources\sxs', ' {IP}\Share\sources\sxs' ]
version_added: "2.1"