mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #8068 from trondhindenes/win_feature_improvements
Updates to the parameters of win_feature
This commit is contained in:
commit
a52cbdbced
2 changed files with 69 additions and 27 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2014, Paul Durivage <paul.durivage@rackspace.com>, and others
|
# (c) 2014, Paul Durivage <paul.durivage@rackspace.com>, Trond Hindenes <trond@hindenes.com> and others
|
||||||
#
|
#
|
||||||
# This file is part of Ansible
|
# This file is part of Ansible
|
||||||
#
|
#
|
||||||
|
@ -52,7 +52,23 @@ options:
|
||||||
- no
|
- no
|
||||||
default: null
|
default: null
|
||||||
aliases: []
|
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 = '''
|
EXAMPLES = '''
|
||||||
|
@ -74,4 +90,8 @@ $ ansible -i hosts -m win_feature -a "name=Web-Server,Web-Common-Http" all
|
||||||
name: "Web-Server"
|
name: "Web-Server"
|
||||||
state: absent
|
state: absent
|
||||||
restart: yes
|
restart: yes
|
||||||
|
include_sub_features: yes
|
||||||
|
include_management_tools: yes
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -47,15 +47,34 @@ Elseif (!$params.state) {
|
||||||
If ($params.restart) {
|
If ($params.restart) {
|
||||||
$restart = $params.restart | ConvertTo-Bool
|
$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") {
|
If ($state -eq "present") {
|
||||||
try {
|
try {
|
||||||
if ($restart) {
|
$featureresult = Add-WindowsFeature -Name $name -Restart:$restart -IncludeAllSubFeature:$includesubfeatures -IncludeManagementTools:$includemanagementtools
|
||||||
$featureresult = Add-WindowsFeature -Name $name -Restart
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$featureresult = Add-WindowsFeature -Name $name
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Fail-Json $result $_.Exception.Message
|
Fail-Json $result $_.Exception.Message
|
||||||
|
@ -63,12 +82,7 @@ If ($state -eq "present") {
|
||||||
}
|
}
|
||||||
Elseif ($state -eq "absent") {
|
Elseif ($state -eq "absent") {
|
||||||
try {
|
try {
|
||||||
if ($restart) {
|
$featureresult = Remove-WindowsFeature -Name $name -Restart:$restart
|
||||||
$featureresult = Remove-WindowsFeature -Name $name -Restart
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$featureresult = Remove-WindowsFeature -Name $name
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Fail-Json $result $_.Exception.Message
|
Fail-Json $result $_.Exception.Message
|
||||||
|
@ -78,6 +92,9 @@ Elseif ($state -eq "absent") {
|
||||||
# Loop through results and create a hash containing details about
|
# Loop through results and create a hash containing details about
|
||||||
# each role/feature that is installed/removed
|
# each role/feature that is installed/removed
|
||||||
$installed_features = @()
|
$installed_features = @()
|
||||||
|
#$featureresult.featureresult is filled if anything was changed
|
||||||
|
if ($featureresult.FeatureResult)
|
||||||
|
{
|
||||||
ForEach ($item in $featureresult.FeatureResult) {
|
ForEach ($item in $featureresult.FeatureResult) {
|
||||||
$installed_features += New-Object psobject @{
|
$installed_features += New-Object psobject @{
|
||||||
id = $item.id.ToString()
|
id = $item.id.ToString()
|
||||||
|
@ -89,12 +106,17 @@ ForEach ($item in $featureresult.FeatureResult) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Set-Attr $result "feature_result" $installed_features
|
Set-Attr $result "feature_result" $installed_features
|
||||||
|
|
||||||
|
|
||||||
|
$result.changed = $true
|
||||||
|
}
|
||||||
|
Else
|
||||||
|
{
|
||||||
|
Set-Attr $result "feature_result" $null
|
||||||
|
}
|
||||||
|
|
||||||
Set-Attr $result "feature_success" $featureresult.Success.ToString()
|
Set-Attr $result "feature_success" $featureresult.Success.ToString()
|
||||||
Set-Attr $result "feature_exitcode" $featureresult.ExitCode.ToString()
|
Set-Attr $result "feature_exitcode" $featureresult.ExitCode.ToString()
|
||||||
Set-Attr $result "feature_restart_needed" $featureresult.RestartNeeded.ToString()
|
Set-Attr $result "feature_restart_needed" $featureresult.RestartNeeded.ToString()
|
||||||
|
|
||||||
If ($result.feature_result.Length -gt 0) {
|
|
||||||
$result.changed = $true
|
|
||||||
}
|
|
||||||
|
|
||||||
Exit-Json $result;
|
Exit-Json $result;
|
||||||
|
|
Loading…
Reference in a new issue