diff --git a/README.md b/README.md index 3ce75b9..aa672fa 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Collection of windows ansible modules. | wsus | wsus_computer_target_group | Add or remove a computer group. | | wsus | wsus_email_notification_setting | Modify email notification settings | | wsus | wsus_install_approval_rule | Modify an update install approval rule | +| wsus | wsus_store_update_location | Modify update file storage location. Store them locally or on Microsoft Update | | wsus | wsus_subscription | Modify the subscription. | ## Release diff --git a/galaxy.yml b/galaxy.yml index ed0bc69..50cab4d 100755 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,6 +1,6 @@ namespace: d_strobel name: windows -version: "1.1.0" +version: "1.2.0" readme: README.md authors: - Dustin Strobel @d-strobel diff --git a/plugins/modules/wsus_store_update_location.ps1 b/plugins/modules/wsus_store_update_location.ps1 new file mode 100644 index 0000000..849d26f --- /dev/null +++ b/plugins/modules/wsus_store_update_location.ps1 @@ -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() \ No newline at end of file diff --git a/plugins/modules/wsus_store_update_location.py b/plugins/modules/wsus_store_update_location.py new file mode 100644 index 0000000..8adf6bf --- /dev/null +++ b/plugins/modules/wsus_store_update_location.py @@ -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) +''' \ No newline at end of file