mirror of https://github.com/ansible/ansible.git
Added win_region module (#19147)
parent
1cc9e9f2a1
commit
a80251ff02
@ -0,0 +1,347 @@
|
|||||||
|
#!powershell
|
||||||
|
# This file is part of Ansible
|
||||||
|
#
|
||||||
|
# Ansible is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Ansible is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
|
$params = Parse-Args -arguments $args -supports_check_mode $true
|
||||||
|
$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
|
||||||
|
|
||||||
|
$result = @{
|
||||||
|
changed = $false
|
||||||
|
warnings = @()
|
||||||
|
restart_required = $false
|
||||||
|
}
|
||||||
|
|
||||||
|
# This is used to get the format values based on the LCType enum based through. When running Vista/7/2008/200R2
|
||||||
|
$lctype_util = @"
|
||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace Ansible {
|
||||||
|
public class LocaleHelper {
|
||||||
|
private String Locale;
|
||||||
|
|
||||||
|
public LocaleHelper(String locale) {
|
||||||
|
Locale = locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||||
|
public static extern int GetLocaleInfoEx(String lpLocaleName, UInt32 LCType, StringBuilder lpLCData, int cchData);
|
||||||
|
|
||||||
|
public String GetValueFromType(UInt32 LCType) {
|
||||||
|
StringBuilder data = new StringBuilder(500);
|
||||||
|
int result = GetLocaleInfoEx(Locale, LCType, data, 500);
|
||||||
|
if (result == 0)
|
||||||
|
throw new Exception(String.Format("Error getting locale info with legacy method: {0}", new Win32Exception(Marshal.GetLastWin32Error()).Message));
|
||||||
|
|
||||||
|
return data.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"@
|
||||||
|
|
||||||
|
Function Get-ValidGeoIds($cultures) {
|
||||||
|
$geo_ids = @()
|
||||||
|
foreach($culture in $cultures) {
|
||||||
|
try {
|
||||||
|
$geo_id = [System.Globalization.RegionInfo]$culture.Name
|
||||||
|
$geo_ids += $geo_id.GeoId
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
$geo_ids
|
||||||
|
}
|
||||||
|
|
||||||
|
Function Test-RegistryProperty($reg_key, $property) {
|
||||||
|
$type = Get-ItemProperty $reg_key -Name $property -ErrorAction SilentlyContinue
|
||||||
|
if ($type -eq $null) {
|
||||||
|
$false
|
||||||
|
} else {
|
||||||
|
$true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($key in Get-ChildItem $source) {
|
||||||
|
$sourceKey = "$source\$($key.PSChildName)"
|
||||||
|
$targetKey = (Get-Item $source).PSChildName
|
||||||
|
Copy-RegistryKey -source "$sourceKey" -target "$target\$targetKey"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# With the legacy options (needed for OS < Windows 8 and Server 2012) we need to check multiple reg
|
||||||
|
# keys and modify them if they need changing. This is because Microsoft only made changing these
|
||||||
|
# values with the newer versions of Windows and didn't backport these features to the older ones,
|
||||||
|
# thanks a bunch there Microsoft :(
|
||||||
|
Function Set-CultureLegacy($culture) {
|
||||||
|
# For when Set-Culture is not available (Pre Windows 8 and Server 2012)
|
||||||
|
$reg_key = 'HKCU:\Control Panel\International'
|
||||||
|
Add-Type -TypeDefinition $lctype_util
|
||||||
|
|
||||||
|
$lookup = New-Object Ansible.LocaleHelper($culture)
|
||||||
|
# hex values are from http://www.pinvoke.net/default.aspx/kernel32/GetLocaleInfoEx.html
|
||||||
|
$wanted_values = New-Object PSObject @{
|
||||||
|
Locale = '{0:x8}' -f ([System.Globalization.CultureInfo]$culture).LCID
|
||||||
|
LocaleName = $culture
|
||||||
|
s1159 = $lookup.GetValueFromType(0x00000028)
|
||||||
|
s2359 = $lookup.GetValueFromType(0x00000029)
|
||||||
|
sCountry = $lookup.GetValueFromType(0x00000006)
|
||||||
|
sCurrency = $lookup.GetValueFromType(0x00000014)
|
||||||
|
sDate = $lookup.GetValueFromType(0x0000001D)
|
||||||
|
sDecimal = $lookup.GetValueFromType(0x0000000E)
|
||||||
|
sGrouping = $lookup.GetValueFromType(0x00000010)
|
||||||
|
sLanguage = $lookup.GetValueFromType(0x00000003) # LOCALE_ABBREVLANGNAME
|
||||||
|
sList = $lookup.GetValueFromType(0x0000000C)
|
||||||
|
sLongDate = $lookup.GetValueFromType(0x00000020)
|
||||||
|
sMonDecimalSep = $lookup.GetValueFromType(0x00000016)
|
||||||
|
sMonGrouping = $lookup.GetValueFromType(0x00000018)
|
||||||
|
sMonThousandSep = $lookup.GetValueFromType(0x00000017)
|
||||||
|
sNativeDigits = $lookup.GetValueFromType(0x00000013)
|
||||||
|
sNegativeSign = $lookup.GetValueFromType(0x00000051)
|
||||||
|
sPositiveSign = $lookup.GetValueFromType(0x00000050)
|
||||||
|
sShortDate = $lookup.GetValueFromType(0x0000001F)
|
||||||
|
sThousand = $lookup.GetValueFromType(0x0000000F)
|
||||||
|
sTime = $lookup.GetValueFromType(0x0000001E)
|
||||||
|
sTimeFormat = $lookup.GetValueFromType(0x00001003)
|
||||||
|
sYearMonth = $lookup.GetValueFromType(0x00001006)
|
||||||
|
iCalendarType = $lookup.GetValueFromType(0x00001009)
|
||||||
|
iCountry = $lookup.GetValueFromType(0x00000005)
|
||||||
|
iCurrDigits = $lookup.GetValueFromType(0x00000019)
|
||||||
|
iCurrency = $lookup.GetValueFromType(0x0000001B)
|
||||||
|
iDate = $lookup.GetValueFromType(0x00000021)
|
||||||
|
iDigits = $lookup.GetValueFromType(0x00000011)
|
||||||
|
NumShape = $lookup.GetValueFromType(0x00001014) # LOCALE_IDIGITSUBSTITUTION
|
||||||
|
iFirstDayOfWeek = $lookup.GetValueFromType(0x0000100C)
|
||||||
|
iFirstWeekOfYear = $lookup.GetValueFromType(0x0000100D)
|
||||||
|
iLZero = $lookup.GetValueFromType(0x00000012)
|
||||||
|
iMeasure = $lookup.GetValueFromType(0x0000000D)
|
||||||
|
iNegCurr = $lookup.GetValueFromType(0x0000001C)
|
||||||
|
iNegNumber = $lookup.GetValueFromType(0x00001010)
|
||||||
|
iPaperSize = $lookup.GetValueFromType(0x0000100A)
|
||||||
|
iTime = $lookup.GetValueFromType(0x00000023)
|
||||||
|
iTimePrefix = $lookup.GetValueFromType(0x00001005)
|
||||||
|
iTLZero = $lookup.GetValueFromType(0x00000025)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Test-RegistryProperty -reg_key $reg_key -property 'sShortTime') {
|
||||||
|
# sShortTime was added after Vista, will check anyway and add in the value if it exists
|
||||||
|
$wanted_values.sShortTime = $lookup.GetValueFromType(0x00000079)
|
||||||
|
}
|
||||||
|
|
||||||
|
$properties = Get-ItemProperty $reg_key
|
||||||
|
foreach($property in $properties.PSObject.Properties) {
|
||||||
|
if (Test-RegistryProperty -reg_key $reg_key -property $property.Name) {
|
||||||
|
$name = $property.Name
|
||||||
|
$old_value = $property.Value
|
||||||
|
$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
|
||||||
|
}
|
||||||
|
$result.changed = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Function Set-SystemLocaleLegacy($unicode_language) {
|
||||||
|
# For when Get/Set-WinSystemLocale is not available (Pre Windows 8 and Server 2012)
|
||||||
|
$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
|
||||||
|
}
|
||||||
|
$result.changed = $true
|
||||||
|
$result.restart_required = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
# This reads from the non registry (Default) key, the extra prop called (Default) see below for more details
|
||||||
|
$current_locale_value = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Locale')."(Default)"
|
||||||
|
$wanted_locale_value = '{0:x8}' -f ([System.Globalization.CultureInfo]$unicode_language).LCID
|
||||||
|
if ($current_locale_value -ne $wanted_locale_value) {
|
||||||
|
# Need to use .net to write property value, Locale has 2 (Default) properties
|
||||||
|
# 1: The actual (Default) property, we don't want to change Set-ItemProperty writes to this value when using (Default)
|
||||||
|
# 2: A property called (Default), this is what we want to change and only .net SetValue can do this one
|
||||||
|
if (-not $check_mode) {
|
||||||
|
$hive = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $env:COMPUTERNAME)
|
||||||
|
$key = $hive.OpenSubKey("SYSTEM\CurrentControlSet\Control\Nls\Locale", $true)
|
||||||
|
$key.SetValue("(Default)", $wanted_locale_value, [Microsoft.Win32.RegistryValueKind]::String)
|
||||||
|
}
|
||||||
|
$result.changed = $true
|
||||||
|
$result.restart_required = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
$codepage_path = 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage'
|
||||||
|
$current_codepage_info = Get-ItemProperty $codepage_path
|
||||||
|
$wanted_codepage_info = ([System.Globalization.CultureInfo]::GetCultureInfo($unicode_language)).TextInfo
|
||||||
|
|
||||||
|
$current_a_cp = $current_codepage_info.ACP
|
||||||
|
$current_oem_cp = $current_codepage_info.OEMCP
|
||||||
|
$current_mac_cp = $current_codepage_info.MACCP
|
||||||
|
$wanted_a_cp = $wanted_codepage_info.ANSICodePage
|
||||||
|
$wanted_oem_cp = $wanted_codepage_info.OEMCodePage
|
||||||
|
$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
|
||||||
|
}
|
||||||
|
$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
|
||||||
|
}
|
||||||
|
$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
|
||||||
|
}
|
||||||
|
$result.changed = $true
|
||||||
|
$result.restart_required = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($format -eq $null -and $location -eq $null -and $unicode_language -eq $null) {
|
||||||
|
Fail-Json $result "An argument for 'format', 'location' or 'unicode_language' needs to be supplied"
|
||||||
|
} else {
|
||||||
|
$valid_cultures = [System.Globalization.CultureInfo]::GetCultures('InstalledWin32Cultures')
|
||||||
|
$valid_geoids = Get-ValidGeoIds -cultures $valid_cultures
|
||||||
|
|
||||||
|
if ($location -ne $null) {
|
||||||
|
if ($valid_geoids -notcontains $location) {
|
||||||
|
Fail-Json $result "The argument location '$location' does not contain a valid Geo ID"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($format -ne $null) {
|
||||||
|
if ($valid_cultures.Name -notcontains $format) {
|
||||||
|
Fail-Json $result "The argument format '$format' does not contain a valid Culture Name"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($unicode_language -ne $null) {
|
||||||
|
if ($valid_cultures.Name -notcontains $unicode_language) {
|
||||||
|
Fail-Json $result "The argument unicode_language '$unicode_language' does not contain a valid Culture Name"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($location -ne $null) {
|
||||||
|
# Get-WinHomeLocation was only added in Server 2012 and above
|
||||||
|
# Use legacy option if older
|
||||||
|
if (Get-Command 'Get-WinHomeLocation' -ErrorAction SilentlyContinue) {
|
||||||
|
$current_location = (Get-WinHomeLocation).GeoId
|
||||||
|
if ($current_location -ne $location) {
|
||||||
|
if (-not $check_mode) {
|
||||||
|
Set-WinHomeLocation -GeoId $location
|
||||||
|
}
|
||||||
|
$result.changed = $true
|
||||||
|
}
|
||||||
|
} 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
|
||||||
|
}
|
||||||
|
$result.changed = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($format -ne $null) {
|
||||||
|
$current_format = (Get-Culture).Name
|
||||||
|
if ($current_format -ne $format) {
|
||||||
|
# Set-Culture was only added in Server 2012 and above, use legacy option if older
|
||||||
|
if (Get-Command 'Set-Culture' -ErrorAction SilentlyContinue) {
|
||||||
|
if (-not $check_mode) {
|
||||||
|
Set-Culture -CultureInfo $format
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Set-CultureLegacy -culture $format
|
||||||
|
}
|
||||||
|
$result.changed = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($unicode_language -ne $null) {
|
||||||
|
# Get/Set-WinSystemLocale was only added in Server 2012 and above, use legacy option if older
|
||||||
|
if (Get-Command 'Get-WinSystemLocale' -ErrorAction SilentlyContinue) {
|
||||||
|
$current_unicode_language = (Get-WinSystemLocale).Name
|
||||||
|
if ($current_unicode_language -ne $unicode_language) {
|
||||||
|
if (-not $check_mode) {
|
||||||
|
Set-WinSystemLocale -SystemLocale $unicode_language
|
||||||
|
}
|
||||||
|
$result.changed = $true
|
||||||
|
$result.restart_required = $true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Set-SystemLocaleLegacy -unicode_language $unicode_language
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($copy_settings -eq $true -and $result.changed -eq $true) {
|
||||||
|
if (-not $check_mode) {
|
||||||
|
$defaultHiveKey = 'HKU\TEMP'
|
||||||
|
reg load $defaultHiveKey 'C:\Users\Default\NTUSER.DAT'
|
||||||
|
New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS
|
||||||
|
|
||||||
|
$sids = 'TEMP', '.DEFAULT', 'S-1-5-19', 'S-1-5-20'
|
||||||
|
foreach ($sid in $sids) {
|
||||||
|
Copy-RegistryKey -source "HKCU:\Keyboard Layout" -target "HKU:\$sid"
|
||||||
|
Copy-RegistryKey -source "HKCU:\Control Panel\International" -target "HKU:\$sid\Control Panel"
|
||||||
|
Copy-RegistryKey -source "HKCU:\Control Panel\Input Method" -target "HKU:\$sid\Control Panel"
|
||||||
|
}
|
||||||
|
|
||||||
|
Remove-PSDrive HKU
|
||||||
|
[gc]::collect()
|
||||||
|
reg unload $defaultHiveKey
|
||||||
|
}
|
||||||
|
$result.changed = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
Exit-Json $result
|
@ -0,0 +1,116 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# (c) 2016, Ansible, inc
|
||||||
|
#
|
||||||
|
# This file is part of Ansible
|
||||||
|
#
|
||||||
|
# Ansible is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Ansible is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
ANSIBLE_METADATA = {'status': ['preview'],
|
||||||
|
'supported_by': 'community',
|
||||||
|
'version': '1.0'}
|
||||||
|
|
||||||
|
DOCUMENTATION = r'''
|
||||||
|
module: win_region
|
||||||
|
version_added: "2.3"
|
||||||
|
short_description: Set the region and format settings
|
||||||
|
description:
|
||||||
|
- Set the location settings of a Windows Server.
|
||||||
|
- Set the format settings of a Windows Server.
|
||||||
|
- Set the unicode language settings of a Windows Server.
|
||||||
|
- Copy across these settings to the default profile.
|
||||||
|
options:
|
||||||
|
location:
|
||||||
|
description:
|
||||||
|
- The location to set for the current user, see
|
||||||
|
U(https://msdn.microsoft.com/en-us/library/dd374073.aspx)
|
||||||
|
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
|
||||||
|
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(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
|
||||||
|
profiles and the welcome screen. This will only run if
|
||||||
|
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)"
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = r'''
|
||||||
|
# Set the region format to English United States
|
||||||
|
- win_region:
|
||||||
|
format: en-US
|
||||||
|
|
||||||
|
# Set the region format to English Australia and copy settings to new profiles
|
||||||
|
- win_region:
|
||||||
|
format: en-AU
|
||||||
|
copy_settings: True
|
||||||
|
|
||||||
|
# Set the unicode language to English Great Britain
|
||||||
|
- win_region:
|
||||||
|
unicode_language: en-GB
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- action: win_reboot
|
||||||
|
when: result.restart_required
|
||||||
|
|
||||||
|
# Set the location to United States
|
||||||
|
- win_region:
|
||||||
|
location: 244
|
||||||
|
|
||||||
|
# Set format, location and unicode to English Australia and copy settings
|
||||||
|
- win_region:
|
||||||
|
location: 12
|
||||||
|
format: en-AU
|
||||||
|
unicode_language: en-AU
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- action: win_reboot
|
||||||
|
when: result.restart_required
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = r'''
|
||||||
|
changed:
|
||||||
|
description: Whether anything was changed
|
||||||
|
returned: always
|
||||||
|
type: boolean
|
||||||
|
sample: True
|
||||||
|
restart_required:
|
||||||
|
description: Whether a reboot is required for the change to take effect
|
||||||
|
returned: success
|
||||||
|
type: boolean
|
||||||
|
sample: True
|
||||||
|
'''
|
@ -0,0 +1 @@
|
|||||||
|
windows/ci/group3
|
@ -0,0 +1,2 @@
|
|||||||
|
dependencies:
|
||||||
|
- prepare_win_tests
|
@ -0,0 +1,252 @@
|
|||||||
|
# test code for the win_region module
|
||||||
|
# This file is part of Ansible
|
||||||
|
#
|
||||||
|
# Ansible is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Ansible is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
- name: expect failure when only setting copy_settings
|
||||||
|
win_region:
|
||||||
|
copy_settings: False
|
||||||
|
register: actual
|
||||||
|
failed_when: actual.msg != "An argument for 'format', 'location' or 'unicode_language' needs to be supplied"
|
||||||
|
|
||||||
|
- name: expect failure when using invalid geo id for the location
|
||||||
|
win_region:
|
||||||
|
location: 111111
|
||||||
|
register: actual
|
||||||
|
failed_when: actual.msg != "The argument location '111111' does not contain a valid Geo ID"
|
||||||
|
|
||||||
|
- name: expect failure when using invalid culture for format
|
||||||
|
win_region:
|
||||||
|
format: ab-CD
|
||||||
|
register: actual
|
||||||
|
failed_when: actual.msg != "The argument format 'ab-CD' does not contain a valid Culture Name"
|
||||||
|
|
||||||
|
- name: expect failure when using invalid culture for unicode_language
|
||||||
|
win_region:
|
||||||
|
unicode_language: ab-CD
|
||||||
|
register: actual
|
||||||
|
failed_when: actual.msg != "The argument unicode_language 'ab-CD' does not contain a valid Culture Name"
|
||||||
|
|
||||||
|
- name: set settings all to English Australia before tests for a baseline
|
||||||
|
win_region:
|
||||||
|
location: 12
|
||||||
|
format: en-AU
|
||||||
|
unicode_language: en-AU
|
||||||
|
|
||||||
|
- name: reboot server to set properties
|
||||||
|
win_reboot:
|
||||||
|
|
||||||
|
- name: check that changing location in check mode works
|
||||||
|
win_region:
|
||||||
|
location: 244
|
||||||
|
register: check_location
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: get current location value
|
||||||
|
win_command: powershell (Get-ItemProperty -Path 'HKCU:\Control Panel\International\Geo').Nation
|
||||||
|
register: actual_location
|
||||||
|
|
||||||
|
- name: check assertion about location change in check mode
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "actual_location.stdout_lines[0] == '12'" # Corresponds to en-AU
|
||||||
|
- "check_location|changed"
|
||||||
|
- "check_location.restart_required == False"
|
||||||
|
|
||||||
|
- name: set location to United States
|
||||||
|
win_region:
|
||||||
|
location: 244
|
||||||
|
register: location
|
||||||
|
|
||||||
|
- name: get current location value
|
||||||
|
win_command: powershell (Get-ItemProperty -Path 'HKCU:\Control Panel\International\Geo').Nation
|
||||||
|
register: actual_location
|
||||||
|
|
||||||
|
- name: check assertion about location change
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "actual_location.stdout_lines[0] == '244'" # Corresponds to en-US
|
||||||
|
- "location|changed"
|
||||||
|
- "location.restart_required == False"
|
||||||
|
|
||||||
|
- name: set location to United States again
|
||||||
|
win_region:
|
||||||
|
location: 244
|
||||||
|
register: location_again
|
||||||
|
|
||||||
|
- name: check that the result did not change
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "not location_again|changed"
|
||||||
|
- "location_again.restart_required == False"
|
||||||
|
|
||||||
|
- name: set format to English United States in check mode
|
||||||
|
win_region:
|
||||||
|
format: en-US
|
||||||
|
register: check_format
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: get actual format value from check mode
|
||||||
|
win_command: powershell (Get-Culture).Name
|
||||||
|
register: actual_format
|
||||||
|
|
||||||
|
- name: check assertion about location change in check mode
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "actual_format.stdout_lines[0] == 'en-AU'"
|
||||||
|
- "check_format|changed"
|
||||||
|
- "check_format.restart_required == False"
|
||||||
|
|
||||||
|
- name: set format to English United States
|
||||||
|
win_region:
|
||||||
|
format: en-US
|
||||||
|
register: format
|
||||||
|
|
||||||
|
- name: get actual format value
|
||||||
|
win_command: powershell (Get-Culture).Name
|
||||||
|
register: actual_format
|
||||||
|
|
||||||
|
- name: check assertion about format change
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "actual_format.stdout_lines[0] == 'en-US'"
|
||||||
|
- "format|changed"
|
||||||
|
- "format.restart_required == False"
|
||||||
|
|
||||||
|
- name: set format to English United States again
|
||||||
|
win_region:
|
||||||
|
format: en-US
|
||||||
|
register: format_again
|
||||||
|
|
||||||
|
- name: check that the result did not change
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "not format_again|changed"
|
||||||
|
- "format_again.restart_required == False"
|
||||||
|
|
||||||
|
- name: set unicode_language to English United States in check mode
|
||||||
|
win_region:
|
||||||
|
unicode_language: en-US
|
||||||
|
register: check_unicode
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: get actual unicode values
|
||||||
|
win_command: powershell (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language').Default
|
||||||
|
register: actual_unicode
|
||||||
|
|
||||||
|
- name: check assertion about unicode language change in check mode
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "actual_unicode.stdout_lines[0] == '0c09'"
|
||||||
|
- "check_unicode|changed"
|
||||||
|
- "check_unicode.restart_required == True"
|
||||||
|
|
||||||
|
- name: set unicode_language to English United States
|
||||||
|
win_region:
|
||||||
|
unicode_language: en-US
|
||||||
|
register: unicode
|
||||||
|
|
||||||
|
- name: reboot the server after changing unicode language
|
||||||
|
action: win_reboot
|
||||||
|
when: unicode.restart_required
|
||||||
|
|
||||||
|
- name: get actual unicode value
|
||||||
|
win_command: powershell (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language').Default
|
||||||
|
register: actual_unicode
|
||||||
|
|
||||||
|
- name: check assertion about unicode language change
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "actual_unicode.stdout_lines[0] == '0409'" # corresponds to en-US
|
||||||
|
- "unicode|changed"
|
||||||
|
- "unicode.restart_required == True"
|
||||||
|
|
||||||
|
- name: set unicode_language to English United States again
|
||||||
|
win_region:
|
||||||
|
unicode_language: en-US
|
||||||
|
register: unicode_again
|
||||||
|
|
||||||
|
- name: check that the result did not change
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "not unicode_again|changed"
|
||||||
|
- "unicode_again.restart_required == False"
|
||||||
|
|
||||||
|
- name: copy settings when setting to the same format check mode
|
||||||
|
win_region:
|
||||||
|
format: en-US
|
||||||
|
copy_settings: True
|
||||||
|
register: check_copy_same
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: check that the result did not change in check mode
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "not check_copy_same|changed"
|
||||||
|
- "check_copy_same.restart_required == False"
|
||||||
|
|
||||||
|
- name: copy settings when setting to the same format
|
||||||
|
win_region:
|
||||||
|
format: en-US
|
||||||
|
copy_settings: True
|
||||||
|
register: copy_same
|
||||||
|
|
||||||
|
- name: check that the result did not change
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "not copy_same|changed"
|
||||||
|
- "copy_same.restart_required == False"
|
||||||
|
|
||||||
|
- name: copy setting when setting to a different format
|
||||||
|
win_region:
|
||||||
|
format: en-GB
|
||||||
|
copy_settings: True
|
||||||
|
register: copy
|
||||||
|
|
||||||
|
- name: get actual format value after copy_settings
|
||||||
|
win_command: powershell (Get-Culture).Name
|
||||||
|
register: actual_copy
|
||||||
|
|
||||||
|
- name: get locale name for local service registry hive
|
||||||
|
win_command: powershell "New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS | Out-Null; (Get-ItemProperty 'HKU:\S-1-5-19\Control Panel\International').LocaleName"
|
||||||
|
register: actual_local
|
||||||
|
|
||||||
|
- name: get locale name for network service registry hive
|
||||||
|
win_command: powershell "New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS | Out-Null; (Get-ItemProperty 'HKU:\S-1-5-20\Control Panel\International').LocaleName"
|
||||||
|
register: actual_network
|
||||||
|
|
||||||
|
- name: load temp hive
|
||||||
|
win_command: reg load HKU\TEMP C:\Users\Default\NTUSER.DAT
|
||||||
|
|
||||||
|
- name: get locale name for default registry hive
|
||||||
|
win_command: powershell "New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS | Out-Null; (Get-ItemProperty 'HKU:\TEMP\Control Panel\International').LocaleName"
|
||||||
|
register: actual_temp
|
||||||
|
|
||||||
|
- name: unload temp hive
|
||||||
|
win_command: reg unload HKU\TEMP
|
||||||
|
|
||||||
|
- name: get locale name for default registry hive
|
||||||
|
win_command: powershell "New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS | Out-Null; (Get-ItemProperty 'HKU:\.DEFAULT\Control Panel\International').LocaleName"
|
||||||
|
register: actual_default
|
||||||
|
|
||||||
|
- name: check assertions about copy setting when setting to a different format
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "actual_copy.stdout_lines[0] == 'en-GB'"
|
||||||
|
- "actual_local.stdout_lines[0] == 'en-GB'"
|
||||||
|
- "actual_network.stdout_lines[0] == 'en-GB'"
|
||||||
|
- "actual_temp.stdout_lines[0] == 'en-GB'"
|
||||||
|
- "actual_default.stdout_lines[0] == 'en-GB'"
|
||||||
|
- "copy|changed"
|
||||||
|
- "copy.restart_required == False"
|
Loading…
Reference in New Issue