From 770ab76ed01f71ffe947140d587f5620b4e90238 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Wed, 8 Mar 2017 16:58:14 +0100 Subject: [PATCH] win_region: Small changes to Add-AnsibleParam and docs (#22310) --- lib/ansible/modules/windows/win_region.ps1 | 53 +++++----------------- lib/ansible/modules/windows/win_region.py | 4 -- 2 files changed, 12 insertions(+), 45 deletions(-) diff --git a/lib/ansible/modules/windows/win_region.ps1 b/lib/ansible/modules/windows/win_region.ps1 index a2c3ab55b88..2b6f3225fac 100644 --- a/lib/ansible/modules/windows/win_region.ps1 +++ b/lib/ansible/modules/windows/win_region.ps1 @@ -18,16 +18,15 @@ # POWERSHELL_COMMON $params = Parse-Args -arguments $args -supports_check_mode $true -$check_mode = Get-AnsibleParam -obj $params "_ansible_check_mode" -type "bool" -default $false +$check_mode = Get-AnsibleParam -obj $params "_ansible_check_mode" -type 'bool' -default $false -$location = Get-AnsibleParam -obj $params -name 'location' -failifempty $false -default $null -$format = Get-AnsibleParam -obj $params -name 'format' -failifempty $false -default $null -$unicode_language = Get-AnsibleParam -obj $params -name 'unicode_language' -failifempty $false -default $null -$copy_settings = Get-AnsibleParam -obj $params -name 'copy_settings' -type "bool" -failifempty $false -default $false +$location = Get-AnsibleParam -obj $params -name 'location' -type 'str' +$format = Get-AnsibleParam -obj $params -name 'format' -type 'str' +$unicode_language = Get-AnsibleParam -obj $params -name 'unicode_language' -type 'str' +$copy_settings = Get-AnsibleParam -obj $params -name 'copy_settings' -type 'bool' -default $false $result = @{ changed = $false - warnings = @() restart_required = $false } @@ -83,11 +82,7 @@ Function Test-RegistryProperty($reg_key, $property) { Function Copy-RegistryKey($source, $target) { # Using Copy-Item -Recurse is giving me weird results, doing it recursively - if ($check_mode) { - Copy-Item -Path $source -Destination $target -WhatIf - } else { - Copy-Item -Path $source -Destination $target - } + Copy-Item -Path $source -Destination $target -WhatIf:$check_mode foreach($key in Get-ChildItem $source) { $sourceKey = "$source\$($key.PSChildName)" @@ -163,11 +158,7 @@ Function Set-CultureLegacy($culture) { $new_value = $wanted_values.$name if ($new_value -ne $old_value) { - if ($check_mode) { - Set-ItemProperty -Path $reg_key -Name $name -Value $new_value -WhatIf - } else { - Set-ItemProperty -Path $reg_key -Name $name -Value $new_value - } + Set-ItemProperty -Path $reg_key -Name $name -Value $new_value -WhatIf:$check_mode $result.changed = $true } } @@ -179,11 +170,7 @@ Function Set-SystemLocaleLegacy($unicode_language) { $current_language_value = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language').Default $wanted_language_value = '{0:x4}' -f ([System.Globalization.CultureInfo]$unicode_language).LCID if ($current_language_value -ne $wanted_language_value) { - if ($check_mode) { - Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language' -Name 'Default' -Value $wanted_language_value -WhatIf - } else { - Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language' -Name 'Default' -Value $wanted_language_value - } + Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language' -Name 'Default' -Value $wanted_language_value -WhatIf:$check_mode $result.changed = $true $result.restart_required = $true } @@ -216,29 +203,17 @@ Function Set-SystemLocaleLegacy($unicode_language) { $wanted_mac_cp = $wanted_codepage_info.MacCodePage if ($current_a_cp -ne $wanted_a_cp) { - if ($check_mode) { - Set-ItemProperty -Path $codepage_path -Name 'ACP' -Value $wanted_a_cp -WhatIf - } else { - Set-ItemProperty -Path $codepage_path -Name 'ACP' -Value $wanted_a_cp - } + Set-ItemProperty -Path $codepage_path -Name 'ACP' -Value $wanted_a_cp -WhatIf:$check_mode $result.changed = $true $result.restart_required = $true } if ($current_oem_cp -ne $wanted_oem_cp) { - if ($check_mode) { - Set-ItemProperty -Path $codepage_path -Name 'OEMCP' -Value $wanted_oem_cp -WhatIf - } else { - Set-ItemProperty -Path $codepage_path -Name 'OEMCP' -Value $wanted_oem_cp - } + Set-ItemProperty -Path $codepage_path -Name 'OEMCP' -Value $wanted_oem_cp -WhatIf:$check_mode $result.changed = $true $result.restart_required = $true } if ($current_mac_cp -ne $wanted_mac_cp) { - if ($check_mode) { - Set-ItemProperty -Path $codepage_path -Name 'MACCP' -Value $wanted_mac_cp -WhatIf - } else { - Set-ItemProperty -Path $codepage_path -Name 'MACCP' -Value $wanted_mac_cp - } + Set-ItemProperty -Path $codepage_path -Name 'MACCP' -Value $wanted_mac_cp -WhatIf:$check_mode $result.changed = $true $result.restart_required = $true } @@ -283,11 +258,7 @@ if ($location -ne $null) { } else { $current_location = (Get-ItemProperty -Path 'HKCU:\Control Panel\International\Geo').Nation if ($current_location -ne $location) { - if ($check_mode) { - Set-ItemProperty -Path 'HKCU:\Control Panel\International\Geo' -Name 'Nation' -Value $location -WhatIf - } else { - Set-ItemProperty -Path 'HKCU:\Control Panel\International\Geo' -Name 'Nation' -Value $location - } + Set-ItemProperty -Path 'HKCU:\Control Panel\International\Geo' -Name 'Nation' -Value $location -WhatIf:$check_mode $result.changed = $true } } diff --git a/lib/ansible/modules/windows/win_region.py b/lib/ansible/modules/windows/win_region.py index c980d2c73ac..9bd932ea138 100644 --- a/lib/ansible/modules/windows/win_region.py +++ b/lib/ansible/modules/windows/win_region.py @@ -40,14 +40,12 @@ options: for a list of GeoIDs you can use and what location it relates to. This needs to be set if C(format) or C(unicode_language) is not set. - required: false format: description: - The language format to set for the current user, see U(https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx) for a list of culture names to use. This needs to be set if C(location) or C(unicode_language) is not set. - required: false unicode_language: description: - The unicode language format to set for all users, see @@ -55,7 +53,6 @@ options: for a list of culture names to use. This needs to be set if C(location) or C(format) is not set. After setting this value a reboot is required for it to take effect. - required: false copy_settings: description: - This will copy the current format and location values to new user @@ -63,7 +60,6 @@ options: C(location), C(format) or C(unicode_language) has resulted in a change. If this process runs then it will always result in a change. - required: false default: false choices: ['true', 'false'] author: "Jordan Borean (@jborean93)"