-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from d-strobel/feat/add-new-module-wsus_store_u…
…pdates_locally Feat/add new module wsus store updates locally
- Loading branch information
Showing
4 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!powershell | ||
|
||
# Copyright: (c) 2023, Dustin Strobel (@d-strobel), Yasmin Hinel (@yahikii), Pascal Breuning (@raumdonut) | ||
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
#AnsibleRequires -CSharpUtil Ansible.Basic | ||
#AnsibleRequires -PowerShell Ansible.ModuleUtils.AddType | ||
|
||
$spec = @{ | ||
options = @{ | ||
update_location = @{ type = "str"; choices = "local", "microsoft_update"; default = "local" } | ||
state = @{ type = "str"; choices = "absent", "present"; default = "present" } | ||
} | ||
supports_check_mode = $false | ||
} | ||
|
||
$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec) | ||
|
||
# Map variables | ||
$updateLocation = $module.Params.update_location | ||
$state = $module.Params.state | ||
|
||
# ErrorAction | ||
$ErrorActionPreference = 'Stop' | ||
|
||
# Get wsus config | ||
try { | ||
$wsus = Get-WsusServer | ||
$configuration = $wsus.GetConfiguration() | ||
} | ||
catch { | ||
$module.FailJson("Failed to get WSUS configuration", $Error[0]) | ||
} | ||
if (($updatelocation -eq "local") -and ($state -eq "absent")) { | ||
try { | ||
$configuration.HostBinariesOnMicrosoftUpdate = $false | ||
$configuration.Save() | ||
} | ||
catch { | ||
$module.FailJson("Failed to set updatefile location to local", $Error[0]) | ||
} | ||
} | ||
elseif (($updatelocation -eq "local") -and ($state -ne "absent")) { | ||
try { | ||
$configuration.HostBinariesOnMicrosoftUpdate = $false | ||
$configuration.Save() | ||
} | ||
catch { | ||
$module.FailJson("Failed to set updatefile location to local", $Error[0]) | ||
} | ||
} | ||
elseif (($updatelocation -eq "microsoft_update") -and ($state -eq "absent")) { | ||
try { | ||
$configuration.HostBinariesOnMicrosoftUpdate = $false | ||
$configuration.Save() | ||
} | ||
catch { | ||
$module.FailJson("Failed to set updatefile location to microsoft_update", $Error[0]) | ||
} | ||
} | ||
elseif (($updatelocation -eq "microsoft_update") -and ($state -ne "absent")) { | ||
try { | ||
$configuration.HostBinariesOnMicrosoftUpdate = $true | ||
$configuration.Save() | ||
} | ||
catch { | ||
$module.FailJson("Failed to set updatefile location to microsoft_update", $Error[0]) | ||
} | ||
} | ||
$module.ExitJson() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright: (c) 2023, Dustin Strobel (@d-strobel), Yasmin Hinel (@yahikii), Pascal Breuning (@raumdonut) | ||
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
DOCUMENTATION = r''' | ||
--- | ||
module: wsus_store_update_location | ||
short_description: Modify the wsus updatefile location. | ||
description: | ||
- Modify the location of the wsus updatefile location. | ||
options: | ||
update_location: | ||
description: | ||
- Set the updatefile location. | ||
type: str | ||
default: local | ||
choices: [ local, microsoft_update ] | ||
state: | ||
description: | ||
- Set to C(present) to ensure the defined settings is present. | ||
- Set to C(absent) to ensure the defined settings are removed. | ||
type: str | ||
default: present | ||
choices: [ absent, present ] | ||
author: | ||
- Pascal Breuning (@raumdonut) | ||
''' |