Skip to content

Commit

Permalink
Merge pull request #8 from d-strobel/feat/add-new-module-wsus_store_u…
Browse files Browse the repository at this point in the history
…pdates_locally

Feat/add new module wsus store updates locally
  • Loading branch information
d-strobel authored Nov 9, 2023
2 parents 644dd0a + b910320 commit 84b8f5f
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
70 changes: 70 additions & 0 deletions plugins/modules/wsus_store_update_location.ps1
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()
30 changes: 30 additions & 0 deletions plugins/modules/wsus_store_update_location.py
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)
'''

0 comments on commit 84b8f5f

Please sign in to comment.