From 0cfffa5dbec3d7aecbd30053032345b5ac929cef Mon Sep 17 00:00:00 2001 From: Trond Hindenes Date: Thu, 7 Jan 2016 19:36:32 +0100 Subject: [PATCH 1/3] Add source as optional parameter --- windows/win_feature.ps1 | 37 +++++++++++++++++++++++++++++++++++-- windows/win_feature.py | 12 +++++++----- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/windows/win_feature.ps1 b/windows/win_feature.ps1 index ec6317fb89b..6104ccb8005 100644 --- a/windows/win_feature.ps1 +++ b/windows/win_feature.ps1 @@ -28,6 +28,7 @@ $result = New-Object PSObject -Property @{ } $name = Get-Attr $params "name" -failifempty $true + $name = $name -split ',' | % { $_.Trim() } $state = Get-Attr $params "state" "present" @@ -39,14 +40,46 @@ If (($state -ne 'present') -and ($state -ne 'absent')) { $restart = Get-Attr $params "restart" $false | ConvertTo-Bool $includesubfeatures = Get-Attr $params "include_sub_features" $false | ConvertTo-Bool $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" + } + } + + $InstallParams = @{ + "Name"=$name; + "Restart"=$Restart; + "IncludeAllSubFeature"=$includesubfeatures; + "ErrorAction"="SilentlyContinue" + } + + if ($IncludeManagementTools -eq $true) + { + $InstallParams.add("IncludeManagementTools";$includemanagementtools) + } + + if ($source -ne $null) + { + $InstallParams.add("Source";$source) + } + + + try { If (Get-Command "Install-WindowsFeature" -ErrorAction SilentlyContinue) { - $featureresult = Install-WindowsFeature -Name $name -Restart:$restart -IncludeAllSubFeature:$includesubfeatures -IncludeManagementTools:$includemanagementtools -ErrorAction SilentlyContinue + $featureresult = Install-WindowsFeature @Params } ElseIf (Get-Command "Add-WindowsFeature" -ErrorAction SilentlyContinue) { - $featureresult = Add-WindowsFeature -Name $name -Restart:$restart -IncludeAllSubFeature:$includesubfeatures -ErrorAction SilentlyContinue + if ($IncludeManagementTools) + { + $Params.Remove("IncludeManagementTools") + } + $featureresult = Add-WindowsFeature @Params } Else { Fail-Json $result "Not supported on this version of Windows" diff --git a/windows/win_feature.py b/windows/win_feature.py index 6ef4774788c..40a8a8585b9 100644 --- a/windows/win_feature.py +++ b/windows/win_feature.py @@ -34,7 +34,6 @@ options: - Names of roles or features to install as a single feature or a comma-separated list of features required: true default: null - aliases: [] state: description: - State of the features or roles on the system @@ -43,7 +42,6 @@ options: - present - absent default: present - aliases: [] restart: description: - Restarts the computer automatically when installation is complete, if restarting is required by the roles or features installed. @@ -51,7 +49,6 @@ options: - yes - no default: null - aliases: [] include_sub_features: description: - Adds all subfeatures of the specified feature @@ -59,7 +56,6 @@ options: - yes - no default: null - aliases: [] include_management_tools: description: - Adds the corresponding management tools to the specified feature @@ -67,7 +63,13 @@ options: - yes - no default: null - aliases: [] + source: + description: + - Specify a source to install the feature from + required: false + choices: + - {driveletter}:\sources\sxs + - \\{IP}\Share\sources\sxs author: - "Paul Durivage (@angstwad)" - "Trond Hindenes (@trondhindenes)" From 3cb70ebc9d1ad2372a1fbec0b3df0309487cc07e Mon Sep 17 00:00:00 2001 From: Trond Hindenes Date: Fri, 8 Jan 2016 14:56:42 +0100 Subject: [PATCH 2/3] bugfix win_feature.ps1 --- windows/win_feature.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/windows/win_feature.ps1 b/windows/win_feature.ps1 index 6104ccb8005..62960d581e3 100644 --- a/windows/win_feature.ps1 +++ b/windows/win_feature.ps1 @@ -60,26 +60,26 @@ If ($state -eq "present") { if ($IncludeManagementTools -eq $true) { - $InstallParams.add("IncludeManagementTools";$includemanagementtools) + $InstallParams.add("IncludeManagementTools",$includemanagementtools) } if ($source -ne $null) { - $InstallParams.add("Source";$source) + $InstallParams.add("Source",$source) } try { If (Get-Command "Install-WindowsFeature" -ErrorAction SilentlyContinue) { - $featureresult = Install-WindowsFeature @Params + $featureresult = Install-WindowsFeature @InstallParams } ElseIf (Get-Command "Add-WindowsFeature" -ErrorAction SilentlyContinue) { if ($IncludeManagementTools) { $Params.Remove("IncludeManagementTools") } - $featureresult = Add-WindowsFeature @Params + $featureresult = Add-WindowsFeature @InstallParams } Else { Fail-Json $result "Not supported on this version of Windows" From 7085a7b884f967950adbc60714b81a422ba18462 Mon Sep 17 00:00:00 2001 From: Trond Hindenes Date: Fri, 8 Jan 2016 15:07:58 +0100 Subject: [PATCH 3/3] update doc --- windows/win_feature.py | 1 + 1 file changed, 1 insertion(+) diff --git a/windows/win_feature.py b/windows/win_feature.py index 40a8a8585b9..6eeda409b3e 100644 --- a/windows/win_feature.py +++ b/windows/win_feature.py @@ -81,6 +81,7 @@ EXAMPLES = ''' # PS C:\Users\Administrator> Import-Module ServerManager; Get-WindowsFeature $ ansible -i hosts -m win_feature -a "name=Web-Server" all $ ansible -i hosts -m win_feature -a "name=Web-Server,Web-Common-Http" all +ansible -m "win_feature" -a "name=NET-Framework-Core source=C:/Temp/iso/sources/sxs" windows # Playbook example