2014-09-26 03:01:01 +02:00
|
|
|
#!powershell
|
|
|
|
# This file is part of Ansible.
|
|
|
|
#
|
|
|
|
# Copyright 2014, Paul Durivage <paul.durivage@rackspace.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
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# WANT_JSON
|
|
|
|
# POWERSHELL_COMMON
|
|
|
|
|
|
|
|
Import-Module Servermanager;
|
|
|
|
|
|
|
|
$params = Parse-Args $args;
|
|
|
|
|
2015-06-22 10:06:48 +02:00
|
|
|
$result = New-Object psobject @{
|
2014-09-26 03:01:01 +02:00
|
|
|
changed = $false
|
|
|
|
}
|
|
|
|
|
2015-08-23 01:01:11 +02:00
|
|
|
$name = Get-Attr $params "name" -failifempty $true
|
|
|
|
$name = $name -split ',' | % { $_.Trim() }
|
2014-09-26 03:01:01 +02:00
|
|
|
|
2015-08-23 01:01:11 +02:00
|
|
|
$state = Get-Attr $params "state" "present"
|
|
|
|
$state = $state.ToString().ToLower()
|
|
|
|
If (($state -ne 'present') -and ($state -ne 'absent')) {
|
|
|
|
Fail-Json $result "state is '$state'; must be 'present' or 'absent'"
|
2014-09-26 03:01:01 +02:00
|
|
|
}
|
|
|
|
|
2015-08-23 01:01:11 +02:00
|
|
|
$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
|
2014-09-26 03:01:01 +02:00
|
|
|
|
2015-06-22 10:06:48 +02:00
|
|
|
$name = $name.split(",")
|
|
|
|
|
|
|
|
|
2014-09-26 03:01:01 +02:00
|
|
|
If ($state -eq "present") {
|
|
|
|
try {
|
2015-06-22 10:06:48 +02:00
|
|
|
|
|
|
|
$featureresult = Add-WindowsFeature -Name $name -Restart:$restart -IncludeAllSubFeature:$includesubfeatures -IncludeManagementTools:$includemanagementtools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-26 03:01:01 +02:00
|
|
|
}
|
|
|
|
catch {
|
|
|
|
Fail-Json $result $_.Exception.Message
|
|
|
|
}
|
|
|
|
}
|
2015-06-22 10:06:48 +02:00
|
|
|
Elseif ($state -eq "absent") {
|
2014-09-26 03:01:01 +02:00
|
|
|
try {
|
2015-06-22 10:06:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$featureresult = Remove-WindowsFeature -Name $name -Restart:$restart
|
2014-09-26 03:01:01 +02:00
|
|
|
}
|
|
|
|
catch {
|
|
|
|
Fail-Json $result $_.Exception.Message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Loop through results and create a hash containing details about
|
|
|
|
# each role/feature that is installed/removed
|
|
|
|
$installed_features = @()
|
|
|
|
#$featureresult.featureresult is filled if anything was changed
|
2015-06-22 10:06:48 +02:00
|
|
|
if ($featureresult.FeatureResult)
|
2014-09-26 03:01:01 +02:00
|
|
|
{
|
|
|
|
ForEach ($item in $featureresult.FeatureResult) {
|
2015-06-22 10:06:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$installed_features += New-Object psobject @{
|
|
|
|
id = $item.id.ToString()
|
2014-09-26 03:01:01 +02:00
|
|
|
display_name = $item.DisplayName
|
2015-06-22 10:06:48 +02:00
|
|
|
|
|
|
|
message = $item.Message
|
|
|
|
restart_needed = $item.RestartNeeded.ToString()
|
2014-09-26 03:01:01 +02:00
|
|
|
skip_reason = $item.SkipReason.ToString()
|
2015-06-22 10:06:48 +02:00
|
|
|
success = $item.Success.ToString()
|
2014-09-26 03:01:01 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-22 10:06:48 +02:00
|
|
|
Set-Attr $result "feature_result" $installed_features
|
|
|
|
|
|
|
|
|
2014-09-26 03:01:01 +02:00
|
|
|
$result.changed = $true
|
|
|
|
}
|
2015-06-22 10:06:48 +02:00
|
|
|
Else
|
|
|
|
{
|
|
|
|
Set-Attr $result "feature_result" $null
|
|
|
|
}
|
2014-09-26 03:01:01 +02:00
|
|
|
|
2015-06-22 10:06:48 +02:00
|
|
|
Set-Attr $result "feature_success" $featureresult.Success.ToString()
|
2014-09-26 03:01:01 +02:00
|
|
|
|
2015-06-22 10:06:48 +02:00
|
|
|
Set-Attr $result "feature_exitcode" $featureresult.ExitCode.ToString()
|
|
|
|
Set-Attr $result "feature_restart_needed" $featureresult.RestartNeeded.ToString()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Exit-Json $result;
|