From 66dad0a6a9d69e7bbc5404339af183b96d54d574 Mon Sep 17 00:00:00 2001 From: Pascal Breuning Date: Tue, 7 Nov 2023 22:42:29 +0100 Subject: [PATCH 1/8] feat: Add new module wsus_store_updates_locally --- .../modules/wsus_store_updates_locally.ps1 | 70 +++++++++++++++++++ plugins/modules/wsus_store_updates_locally.py | 30 ++++++++ 2 files changed, 100 insertions(+) create mode 100644 plugins/modules/wsus_store_updates_locally.ps1 create mode 100644 plugins/modules/wsus_store_updates_locally.py diff --git a/plugins/modules/wsus_store_updates_locally.ps1 b/plugins/modules/wsus_store_updates_locally.ps1 new file mode 100644 index 0000000..0fb1113 --- /dev/null +++ b/plugins/modules/wsus_store_updates_locally.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_updates_locally.py b/plugins/modules/wsus_store_updates_locally.py new file mode 100644 index 0000000..c1c5a69 --- /dev/null +++ b/plugins/modules/wsus_store_updates_locally.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_updates_locally +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 From e47b48c6570c92166d2913de2f315be864079051 Mon Sep 17 00:00:00 2001 From: Pascal Breuning Date: Tue, 7 Nov 2023 22:43:03 +0100 Subject: [PATCH 2/8] docs: Add new module to table --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3ce75b9..49de9b1 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_updates_locally | Modify update file storage location. Store them locally or on Microsoft Update | | wsus | wsus_subscription | Modify the subscription. | ## Release From 1eef32cced4f0a642eac2329576cf553b967cf1f Mon Sep 17 00:00:00 2001 From: Pascal Breuning Date: Tue, 7 Nov 2023 22:53:16 +0100 Subject: [PATCH 3/8] chore: Remove unnecessary whitespace --- plugins/modules/wsus_store_updates_locally.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/wsus_store_updates_locally.ps1 b/plugins/modules/wsus_store_updates_locally.ps1 index 0fb1113..d0f27b8 100644 --- a/plugins/modules/wsus_store_updates_locally.ps1 +++ b/plugins/modules/wsus_store_updates_locally.ps1 @@ -8,8 +8,8 @@ $spec = @{ options = @{ - update_location = @{ type = "str"; choices = "local", "microsoft_update"; default = "local"} - state = @{ type = "str"; choices = "absent", "present"; default = "present" } + update_location = @{ type = "str"; choices = "local", "microsoft_update"; default = "local" } + state = @{ type = "str"; choices = "absent", "present"; default = "present" } } supports_check_mode = $false } From 097806d3c35f7d3b06b92245d4571d6f536c00ff Mon Sep 17 00:00:00 2001 From: raumdonut Date: Thu, 9 Nov 2023 10:13:08 +0100 Subject: [PATCH 4/8] chore: Update module naming --- ...s_store_updates_locally.ps1 => wsus_store_update_location.ps1} | 0 ...sus_store_updates_locally.py => wsus_store_update_location.py} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename plugins/modules/{wsus_store_updates_locally.ps1 => wsus_store_update_location.ps1} (100%) rename plugins/modules/{wsus_store_updates_locally.py => wsus_store_update_location.py} (100%) diff --git a/plugins/modules/wsus_store_updates_locally.ps1 b/plugins/modules/wsus_store_update_location.ps1 similarity index 100% rename from plugins/modules/wsus_store_updates_locally.ps1 rename to plugins/modules/wsus_store_update_location.ps1 diff --git a/plugins/modules/wsus_store_updates_locally.py b/plugins/modules/wsus_store_update_location.py similarity index 100% rename from plugins/modules/wsus_store_updates_locally.py rename to plugins/modules/wsus_store_update_location.py From 4ae44c08f016612d0331e3858799079029e44a64 Mon Sep 17 00:00:00 2001 From: raumdonut Date: Thu, 9 Nov 2023 10:13:43 +0100 Subject: [PATCH 5/8] chore: change var naming to camelcase --- plugins/modules/wsus_store_update_location.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/wsus_store_update_location.ps1 b/plugins/modules/wsus_store_update_location.ps1 index d0f27b8..849d26f 100644 --- a/plugins/modules/wsus_store_update_location.ps1 +++ b/plugins/modules/wsus_store_update_location.ps1 @@ -17,7 +17,7 @@ $spec = @{ $module = [Ansible.Basic.AnsibleModule]::Create($args, $spec) # Map variables -$updatelocation = $module.Params.update_location +$updateLocation = $module.Params.update_location $state = $module.Params.state # ErrorAction From 1da2777c7e3bfffa963e9bff4133d2cc51771984 Mon Sep 17 00:00:00 2001 From: raumdonut Date: Thu, 9 Nov 2023 10:14:04 +0100 Subject: [PATCH 6/8] docs: Update readme with new module name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 49de9b1..aa672fa 100644 --- a/README.md +++ b/README.md @@ -26,7 +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_updates_locally | Modify update file storage location. Store them locally or on Microsoft Update | +| wsus | wsus_store_update_location | Modify update file storage location. Store them locally or on Microsoft Update | | wsus | wsus_subscription | Modify the subscription. | ## Release From 02f0c3f262183b26689339abf208cf236182899c Mon Sep 17 00:00:00 2001 From: raumdonut Date: Thu, 9 Nov 2023 10:15:58 +0100 Subject: [PATCH 7/8] chore: Update module naming --- plugins/modules/wsus_store_update_location.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/wsus_store_update_location.py b/plugins/modules/wsus_store_update_location.py index c1c5a69..8adf6bf 100644 --- a/plugins/modules/wsus_store_update_location.py +++ b/plugins/modules/wsus_store_update_location.py @@ -6,7 +6,7 @@ DOCUMENTATION = r''' --- -module: wsus_store_updates_locally +module: wsus_store_update_location short_description: Modify the wsus updatefile location. description: - Modify the location of the wsus updatefile location. From b91032097e51395a1e142a1651b540e33187295d Mon Sep 17 00:00:00 2001 From: Dustin Strobel Date: Thu, 9 Nov 2023 12:58:47 +0100 Subject: [PATCH 8/8] chore: Bump galaxy version for release --- galaxy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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