From 8e16962596297479f22d6fabd2d93e3fd1b1845f Mon Sep 17 00:00:00 2001 From: Trond Hindenes Date: Tue, 8 Jul 2014 18:04:12 +0200 Subject: [PATCH 1/2] improvements to win_feature --- windows/win_feature | 24 ++++++++++++++++++++++-- windows/win_feature.ps1 | 38 ++++++++++++++++++++++++++------------ 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/windows/win_feature b/windows/win_feature index 9e1a9cef5d9..ef344ee3b22 100644 --- a/windows/win_feature +++ b/windows/win_feature @@ -1,7 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# (c) 2014, Paul Durivage , and others +# (c) 2014, Paul Durivage , Trond Hindenes and others # # This file is part of Ansible # @@ -52,7 +52,23 @@ options: - no default: null aliases: [] -author: Paul Durivage + include_sub_features: + description: + - Adds all subfeatures of the specified feature + choices: + - yes + - no + default: null + aliases: [] + include_management_tools: + description: + - Adds the corresponding management tools to the specified feature + choices: + - yes + - no + default: null + aliases: [] +author: Paul Durivage / Trond Hindenes ''' EXAMPLES = ''' @@ -74,4 +90,8 @@ $ ansible -i hosts -m win_feature -a "name=Web-Server,Web-Common-Http" all name: "Web-Server" state: absent restart: yes + include_sub_features: yes + include_management_tools: yes + + ''' diff --git a/windows/win_feature.ps1 b/windows/win_feature.ps1 index 698d78dfcad..522cced33bc 100644 --- a/windows/win_feature.ps1 +++ b/windows/win_feature.ps1 @@ -47,15 +47,34 @@ Elseif (!$params.state) { If ($params.restart) { $restart = $params.restart | ConvertTo-Bool } +Else +{ + $restart = $false +} + +if ($params.include_sub_features) +{ + $includesubfeatures = $params.include_sub_features | ConvertTo-Bool +} +Else +{ + $includesubfeatures = $false +} + +if ($params.include_management_tools) +{ + $includemanagementtools = $params.include_management_tools | ConvertTo-Bool +} +Else +{ + $includemanagementtools = $false +} + + If ($state -eq "present") { try { - if ($restart) { - $featureresult = Add-WindowsFeature -Name $name -Restart - } - else { - $featureresult = Add-WindowsFeature -Name $name - } + $featureresult = Add-WindowsFeature -Name $name -Restart:$restart -IncludeAllSubFeature:$includesubfeatures -IncludeManagementTools:$includemanagementtools } catch { Fail-Json $result $_.Exception.Message @@ -63,12 +82,7 @@ If ($state -eq "present") { } Elseif ($state -eq "absent") { try { - if ($restart) { - $featureresult = Remove-WindowsFeature -Name $name -Restart - } - else { - $featureresult = Remove-WindowsFeature -Name $name - } + $featureresult = Remove-WindowsFeature -Name $name -Restart:$restart } catch { Fail-Json $result $_.Exception.Message From ba507553b093e24d95aff85634c97a471667db54 Mon Sep 17 00:00:00 2001 From: Trond Hindenes Date: Thu, 10 Jul 2014 12:00:00 +0200 Subject: [PATCH 2/2] Better result handling --- windows/win_feature.ps1 | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/windows/win_feature.ps1 b/windows/win_feature.ps1 index 522cced33bc..a0776a4bf1a 100644 --- a/windows/win_feature.ps1 +++ b/windows/win_feature.ps1 @@ -92,23 +92,31 @@ Elseif ($state -eq "absent") { # Loop through results and create a hash containing details about # each role/feature that is installed/removed $installed_features = @() -ForEach ($item in $featureresult.FeatureResult) { - $installed_features += New-Object psobject @{ - id = $item.id.ToString() - display_name = $item.DisplayName - message = $item.Message.ToString() - restart_needed = $item.RestartNeeded.ToString() - skip_reason = $item.SkipReason.ToString() - success = $item.Success.ToString() +#$featureresult.featureresult is filled if anything was changed +if ($featureresult.FeatureResult) +{ + ForEach ($item in $featureresult.FeatureResult) { + $installed_features += New-Object psobject @{ + id = $item.id.ToString() + display_name = $item.DisplayName + message = $item.Message.ToString() + restart_needed = $item.RestartNeeded.ToString() + skip_reason = $item.SkipReason.ToString() + success = $item.Success.ToString() + } } + Set-Attr $result "feature_result" $installed_features + + + $result.changed = $true +} +Else +{ + Set-Attr $result "feature_result" $null } -Set-Attr $result "feature_result" $installed_features + Set-Attr $result "feature_success" $featureresult.Success.ToString() Set-Attr $result "feature_exitcode" $featureresult.ExitCode.ToString() Set-Attr $result "feature_restart_needed" $featureresult.RestartNeeded.ToString() -If ($result.feature_result.Length -gt 0) { - $result.changed = $true -} - Exit-Json $result;