253 | 254 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,347 @@ |
0 |
+#!powershell |
|
1 |
+# This file is part of Ansible |
|
2 |
+# |
|
3 |
+# Ansible is free software: you can redistribute it and/or modify |
|
4 |
+# it under the terms of the GNU General Public License as published by |
|
5 |
+# the Free Software Foundation, either version 3 of the License, or |
|
6 |
+# (at your option) any later version. |
|
7 |
+# |
|
8 |
+# Ansible is distributed in the hope that it will be useful, |
|
9 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
+# GNU General Public License for more details. |
|
12 |
+# |
|
13 |
+# You should have received a copy of the GNU General Public License |
|
14 |
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
|
15 |
+ |
|
16 |
+# WANT_JSON |
|
17 |
+# POWERSHELL_COMMON |
|
18 |
+ |
|
19 |
+$params = Parse-Args -arguments $args -supports_check_mode $true |
|
20 |
+$check_mode = Get-AnsibleParam -obj $params "_ansible_check_mode" -type "bool" -default $false |
|
21 |
+ |
|
22 |
+$location = Get-AnsibleParam -obj $params -name 'location' -failifempty $false -default $null |
|
23 |
+$format = Get-AnsibleParam -obj $params -name 'format' -failifempty $false -default $null |
|
24 |
+$unicode_language = Get-AnsibleParam -obj $params -name 'unicode_language' -failifempty $false -default $null |
|
25 |
+$copy_settings = Get-AnsibleParam -obj $params -name 'copy_settings' -type "bool" -failifempty $false -default $false |
|
26 |
+ |
|
27 |
+$result = @{ |
|
28 |
+ changed = $false |
|
29 |
+ warnings = @() |
|
30 |
+ restart_required = $false |
|
31 |
+} |
|
32 |
+ |
|
33 |
+# This is used to get the format values based on the LCType enum based through. When running Vista/7/2008/200R2 |
|
34 |
+$lctype_util = @" |
|
35 |
+using System; |
|
36 |
+using System.Text; |
|
37 |
+using System.Runtime.InteropServices; |
|
38 |
+using System.ComponentModel; |
|
39 |
+ |
|
40 |
+namespace Ansible { |
|
41 |
+ public class LocaleHelper { |
|
42 |
+ private String Locale; |
|
43 |
+ |
|
44 |
+ public LocaleHelper(String locale) { |
|
45 |
+ Locale = locale; |
|
46 |
+ } |
|
47 |
+ |
|
48 |
+ [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] |
|
49 |
+ public static extern int GetLocaleInfoEx(String lpLocaleName, UInt32 LCType, StringBuilder lpLCData, int cchData); |
|
50 |
+ |
|
51 |
+ public String GetValueFromType(UInt32 LCType) { |
|
52 |
+ StringBuilder data = new StringBuilder(500); |
|
53 |
+ int result = GetLocaleInfoEx(Locale, LCType, data, 500); |
|
54 |
+ if (result == 0) |
|
55 |
+ throw new Exception(String.Format("Error getting locale info with legacy method: {0}", new Win32Exception(Marshal.GetLastWin32Error()).Message)); |
|
56 |
+ |
|
57 |
+ return data.ToString(); |
|
58 |
+ } |
|
59 |
+ } |
|
60 |
+} |
|
61 |
+"@ |
|
62 |
+ |
|
63 |
+Function Get-ValidGeoIds($cultures) { |
|
64 |
+ $geo_ids = @() |
|
65 |
+ foreach($culture in $cultures) { |
|
66 |
+ try { |
|
67 |
+ $geo_id = [System.Globalization.RegionInfo]$culture.Name |
|
68 |
+ $geo_ids += $geo_id.GeoId |
|
69 |
+ } catch {} |
|
70 |
+ } |
|
71 |
+ $geo_ids |
|
72 |
+} |
|
73 |
+ |
|
74 |
+Function Test-RegistryProperty($reg_key, $property) { |
|
75 |
+ $type = Get-ItemProperty $reg_key -Name $property -ErrorAction SilentlyContinue |
|
76 |
+ if ($type -eq $null) { |
|
77 |
+ $false |
|
78 |
+ } else { |
|
79 |
+ $true |
|
80 |
+ } |
|
81 |
+} |
|
82 |
+ |
|
83 |
+Function Copy-RegistryKey($source, $target) { |
|
84 |
+ # Using Copy-Item -Recurse is giving me weird results, doing it recursively |
|
85 |
+ if ($check_mode) { |
|
86 |
+ Copy-Item -Path $source -Destination $target -WhatIf |
|
87 |
+ } else { |
|
88 |
+ Copy-Item -Path $source -Destination $target |
|
89 |
+ } |
|
90 |
+ |
|
91 |
+ foreach($key in Get-ChildItem $source) { |
|
92 |
+ $sourceKey = "$source\$($key.PSChildName)" |
|
93 |
+ $targetKey = (Get-Item $source).PSChildName |
|
94 |
+ Copy-RegistryKey -source "$sourceKey" -target "$target\$targetKey" |
|
95 |
+ } |
|
96 |
+} |
|
97 |
+ |
|
98 |
+# With the legacy options (needed for OS < Windows 8 and Server 2012) we need to check multiple reg |
|
99 |
+# keys and modify them if they need changing. This is because Microsoft only made changing these |
|
100 |
+# values with the newer versions of Windows and didn't backport these features to the older ones, |
|
101 |
+# thanks a bunch there Microsoft :( |
|
102 |
+Function Set-CultureLegacy($culture) { |
|
103 |
+ # For when Set-Culture is not available (Pre Windows 8 and Server 2012) |
|
104 |
+ $reg_key = 'HKCU:\Control Panel\International' |
|
105 |
+ Add-Type -TypeDefinition $lctype_util |
|
106 |
+ |
|
107 |
+ $lookup = New-Object Ansible.LocaleHelper($culture) |
|
108 |
+ # hex values are from http://www.pinvoke.net/default.aspx/kernel32/GetLocaleInfoEx.html |
|
109 |
+ $wanted_values = New-Object PSObject @{ |
|
110 |
+ Locale = '{0:x8}' -f ([System.Globalization.CultureInfo]$culture).LCID |
|
111 |
+ LocaleName = $culture |
|
112 |
+ s1159 = $lookup.GetValueFromType(0x00000028) |
|
113 |
+ s2359 = $lookup.GetValueFromType(0x00000029) |
|
114 |
+ sCountry = $lookup.GetValueFromType(0x00000006) |
|
115 |
+ sCurrency = $lookup.GetValueFromType(0x00000014) |
|
116 |
+ sDate = $lookup.GetValueFromType(0x0000001D) |
|
117 |
+ sDecimal = $lookup.GetValueFromType(0x0000000E) |
|
118 |
+ sGrouping = $lookup.GetValueFromType(0x00000010) |
|
119 |
+ sLanguage = $lookup.GetValueFromType(0x00000003) # LOCALE_ABBREVLANGNAME |
|
120 |
+ sList = $lookup.GetValueFromType(0x0000000C) |
|
121 |
+ sLongDate = $lookup.GetValueFromType(0x00000020) |
|
122 |
+ sMonDecimalSep = $lookup.GetValueFromType(0x00000016) |
|
123 |
+ sMonGrouping = $lookup.GetValueFromType(0x00000018) |
|
124 |
+ sMonThousandSep = $lookup.GetValueFromType(0x00000017) |
|
125 |
+ sNativeDigits = $lookup.GetValueFromType(0x00000013) |
|
126 |
+ sNegativeSign = $lookup.GetValueFromType(0x00000051) |
|
127 |
+ sPositiveSign = $lookup.GetValueFromType(0x00000050) |
|
128 |
+ sShortDate = $lookup.GetValueFromType(0x0000001F) |
|
129 |
+ sThousand = $lookup.GetValueFromType(0x0000000F) |
|
130 |
+ sTime = $lookup.GetValueFromType(0x0000001E) |
|
131 |
+ sTimeFormat = $lookup.GetValueFromType(0x00001003) |
|
132 |
+ sYearMonth = $lookup.GetValueFromType(0x00001006) |
|
133 |
+ iCalendarType = $lookup.GetValueFromType(0x00001009) |
|
134 |
+ iCountry = $lookup.GetValueFromType(0x00000005) |
|
135 |
+ iCurrDigits = $lookup.GetValueFromType(0x00000019) |
|
136 |
+ iCurrency = $lookup.GetValueFromType(0x0000001B) |
|
137 |
+ iDate = $lookup.GetValueFromType(0x00000021) |
|
138 |
+ iDigits = $lookup.GetValueFromType(0x00000011) |
|
139 |
+ NumShape = $lookup.GetValueFromType(0x00001014) # LOCALE_IDIGITSUBSTITUTION |
|
140 |
+ iFirstDayOfWeek = $lookup.GetValueFromType(0x0000100C) |
|
141 |
+ iFirstWeekOfYear = $lookup.GetValueFromType(0x0000100D) |
|
142 |
+ iLZero = $lookup.GetValueFromType(0x00000012) |
|
143 |
+ iMeasure = $lookup.GetValueFromType(0x0000000D) |
|
144 |
+ iNegCurr = $lookup.GetValueFromType(0x0000001C) |
|
145 |
+ iNegNumber = $lookup.GetValueFromType(0x00001010) |
|
146 |
+ iPaperSize = $lookup.GetValueFromType(0x0000100A) |
|
147 |
+ iTime = $lookup.GetValueFromType(0x00000023) |
|
148 |
+ iTimePrefix = $lookup.GetValueFromType(0x00001005) |
|
149 |
+ iTLZero = $lookup.GetValueFromType(0x00000025) |
|
150 |
+ } |
|
151 |
+ |
|
152 |
+ if (Test-RegistryProperty -reg_key $reg_key -property 'sShortTime') { |
|
153 |
+ # sShortTime was added after Vista, will check anyway and add in the value if it exists |
|
154 |
+ $wanted_values.sShortTime = $lookup.GetValueFromType(0x00000079) |
|
155 |
+ } |
|
156 |
+ |
|
157 |
+ $properties = Get-ItemProperty $reg_key |
|
158 |
+ foreach($property in $properties.PSObject.Properties) { |
|
159 |
+ if (Test-RegistryProperty -reg_key $reg_key -property $property.Name) { |
|
160 |
+ $name = $property.Name |
|
161 |
+ $old_value = $property.Value |
|
162 |
+ $new_value = $wanted_values.$name |
|
163 |
+ |
|
164 |
+ if ($new_value -ne $old_value) { |
|
165 |
+ if ($check_mode) { |
|
166 |
+ Set-ItemProperty -Path $reg_key -Name $name -Value $new_value -WhatIf |
|
167 |
+ } else { |
|
168 |
+ Set-ItemProperty -Path $reg_key -Name $name -Value $new_value |
|
169 |
+ } |
|
170 |
+ $result.changed = $true |
|
171 |
+ } |
|
172 |
+ } |
|
173 |
+ } |
|
174 |
+} |
|
175 |
+ |
|
176 |
+Function Set-SystemLocaleLegacy($unicode_language) { |
|
177 |
+ # For when Get/Set-WinSystemLocale is not available (Pre Windows 8 and Server 2012) |
|
178 |
+ $current_language_value = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language').Default |
|
179 |
+ $wanted_language_value = '{0:x4}' -f ([System.Globalization.CultureInfo]$unicode_language).LCID |
|
180 |
+ if ($current_language_value -ne $wanted_language_value) { |
|
181 |
+ if ($check_mode) { |
|
182 |
+ Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language' -Name 'Default' -Value $wanted_language_value -WhatIf |
|
183 |
+ } else { |
|
184 |
+ Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language' -Name 'Default' -Value $wanted_language_value |
|
185 |
+ } |
|
186 |
+ $result.changed = $true |
|
187 |
+ $result.restart_required = $true |
|
188 |
+ } |
|
189 |
+ |
|
190 |
+ # This reads from the non registry (Default) key, the extra prop called (Default) see below for more details |
|
191 |
+ $current_locale_value = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Locale')."(Default)" |
|
192 |
+ $wanted_locale_value = '{0:x8}' -f ([System.Globalization.CultureInfo]$unicode_language).LCID |
|
193 |
+ if ($current_locale_value -ne $wanted_locale_value) { |
|
194 |
+ # Need to use .net to write property value, Locale has 2 (Default) properties |
|
195 |
+ # 1: The actual (Default) property, we don't want to change Set-ItemProperty writes to this value when using (Default) |
|
196 |
+ # 2: A property called (Default), this is what we want to change and only .net SetValue can do this one |
|
197 |
+ if (-not $check_mode) { |
|
198 |
+ $hive = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $env:COMPUTERNAME) |
|
199 |
+ $key = $hive.OpenSubKey("SYSTEM\CurrentControlSet\Control\Nls\Locale", $true) |
|
200 |
+ $key.SetValue("(Default)", $wanted_locale_value, [Microsoft.Win32.RegistryValueKind]::String) |
|
201 |
+ } |
|
202 |
+ $result.changed = $true |
|
203 |
+ $result.restart_required = $true |
|
204 |
+ } |
|
205 |
+ |
|
206 |
+ $codepage_path = 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage' |
|
207 |
+ $current_codepage_info = Get-ItemProperty $codepage_path |
|
208 |
+ $wanted_codepage_info = ([System.Globalization.CultureInfo]::GetCultureInfo($unicode_language)).TextInfo |
|
209 |
+ |
|
210 |
+ $current_a_cp = $current_codepage_info.ACP |
|
211 |
+ $current_oem_cp = $current_codepage_info.OEMCP |
|
212 |
+ $current_mac_cp = $current_codepage_info.MACCP |
|
213 |
+ $wanted_a_cp = $wanted_codepage_info.ANSICodePage |
|
214 |
+ $wanted_oem_cp = $wanted_codepage_info.OEMCodePage |
|
215 |
+ $wanted_mac_cp = $wanted_codepage_info.MacCodePage |
|
216 |
+ |
|
217 |
+ if ($current_a_cp -ne $wanted_a_cp) { |
|
218 |
+ if ($check_mode) { |
|
219 |
+ Set-ItemProperty -Path $codepage_path -Name 'ACP' -Value $wanted_a_cp -WhatIf |
|
220 |
+ } else { |
|
221 |
+ Set-ItemProperty -Path $codepage_path -Name 'ACP' -Value $wanted_a_cp |
|
222 |
+ } |
|
223 |
+ $result.changed = $true |
|
224 |
+ $result.restart_required = $true |
|
225 |
+ } |
|
226 |
+ if ($current_oem_cp -ne $wanted_oem_cp) { |
|
227 |
+ if ($check_mode) { |
|
228 |
+ Set-ItemProperty -Path $codepage_path -Name 'OEMCP' -Value $wanted_oem_cp -WhatIf |
|
229 |
+ } else { |
|
230 |
+ Set-ItemProperty -Path $codepage_path -Name 'OEMCP' -Value $wanted_oem_cp |
|
231 |
+ } |
|
232 |
+ $result.changed = $true |
|
233 |
+ $result.restart_required = $true |
|
234 |
+ } |
|
235 |
+ if ($current_mac_cp -ne $wanted_mac_cp) { |
|
236 |
+ if ($check_mode) { |
|
237 |
+ Set-ItemProperty -Path $codepage_path -Name 'MACCP' -Value $wanted_mac_cp -WhatIf |
|
238 |
+ } else { |
|
239 |
+ Set-ItemProperty -Path $codepage_path -Name 'MACCP' -Value $wanted_mac_cp |
|
240 |
+ } |
|
241 |
+ $result.changed = $true |
|
242 |
+ $result.restart_required = $true |
|
243 |
+ } |
|
244 |
+} |
|
245 |
+ |
|
246 |
+if ($format -eq $null -and $location -eq $null -and $unicode_language -eq $null) { |
|
247 |
+ Fail-Json $result "An argument for 'format', 'location' or 'unicode_language' needs to be supplied" |
|
248 |
+} else { |
|
249 |
+ $valid_cultures = [System.Globalization.CultureInfo]::GetCultures('InstalledWin32Cultures') |
|
250 |
+ $valid_geoids = Get-ValidGeoIds -cultures $valid_cultures |
|
251 |
+ |
|
252 |
+ if ($location -ne $null) { |
|
253 |
+ if ($valid_geoids -notcontains $location) { |
|
254 |
+ Fail-Json $result "The argument location '$location' does not contain a valid Geo ID" |
|
255 |
+ } |
|
256 |
+ } |
|
257 |
+ |
|
258 |
+ if ($format -ne $null) { |
|
259 |
+ if ($valid_cultures.Name -notcontains $format) { |
|
260 |
+ Fail-Json $result "The argument format '$format' does not contain a valid Culture Name" |
|
261 |
+ } |
|
262 |
+ } |
|
263 |
+ |
|
264 |
+ if ($unicode_language -ne $null) { |
|
265 |
+ if ($valid_cultures.Name -notcontains $unicode_language) { |
|
266 |
+ Fail-Json $result "The argument unicode_language '$unicode_language' does not contain a valid Culture Name" |
|
267 |
+ } |
|
268 |
+ } |
|
269 |
+} |
|
270 |
+ |
|
271 |
+if ($location -ne $null) { |
|
272 |
+ # Get-WinHomeLocation was only added in Server 2012 and above |
|
273 |
+ # Use legacy option if older |
|
274 |
+ if (Get-Command 'Get-WinHomeLocation' -ErrorAction SilentlyContinue) { |
|
275 |
+ $current_location = (Get-WinHomeLocation).GeoId |
|
276 |
+ if ($current_location -ne $location) { |
|
277 |
+ if (-not $check_mode) { |
|
278 |
+ Set-WinHomeLocation -GeoId $location |
|
279 |
+ } |
|
280 |
+ $result.changed = $true |
|
281 |
+ } |
|
282 |
+ } else { |
|
283 |
+ $current_location = (Get-ItemProperty -Path 'HKCU:\Control Panel\International\Geo').Nation |
|
284 |
+ if ($current_location -ne $location) { |
|
285 |
+ if ($check_mode) { |
|
286 |
+ Set-ItemProperty -Path 'HKCU:\Control Panel\International\Geo' -Name 'Nation' -Value $location -WhatIf |
|
287 |
+ } else { |
|
288 |
+ Set-ItemProperty -Path 'HKCU:\Control Panel\International\Geo' -Name 'Nation' -Value $location |
|
289 |
+ } |
|
290 |
+ $result.changed = $true |
|
291 |
+ } |
|
292 |
+ } |
|
293 |
+} |
|
294 |
+ |
|
295 |
+if ($format -ne $null) { |
|
296 |
+ $current_format = (Get-Culture).Name |
|
297 |
+ if ($current_format -ne $format) { |
|
298 |
+ # Set-Culture was only added in Server 2012 and above, use legacy option if older |
|
299 |
+ if (Get-Command 'Set-Culture' -ErrorAction SilentlyContinue) { |
|
300 |
+ if (-not $check_mode) { |
|
301 |
+ Set-Culture -CultureInfo $format |
|
302 |
+ } |
|
303 |
+ } else { |
|
304 |
+ Set-CultureLegacy -culture $format |
|
305 |
+ } |
|
306 |
+ $result.changed = $true |
|
307 |
+ } |
|
308 |
+} |
|
309 |
+ |
|
310 |
+if ($unicode_language -ne $null) { |
|
311 |
+ # Get/Set-WinSystemLocale was only added in Server 2012 and above, use legacy option if older |
|
312 |
+ if (Get-Command 'Get-WinSystemLocale' -ErrorAction SilentlyContinue) { |
|
313 |
+ $current_unicode_language = (Get-WinSystemLocale).Name |
|
314 |
+ if ($current_unicode_language -ne $unicode_language) { |
|
315 |
+ if (-not $check_mode) { |
|
316 |
+ Set-WinSystemLocale -SystemLocale $unicode_language |
|
317 |
+ } |
|
318 |
+ $result.changed = $true |
|
319 |
+ $result.restart_required = $true |
|
320 |
+ } |
|
321 |
+ } else { |
|
322 |
+ Set-SystemLocaleLegacy -unicode_language $unicode_language |
|
323 |
+ } |
|
324 |
+} |
|
325 |
+ |
|
326 |
+if ($copy_settings -eq $true -and $result.changed -eq $true) { |
|
327 |
+ if (-not $check_mode) { |
|
328 |
+ $defaultHiveKey = 'HKU\TEMP' |
|
329 |
+ reg load $defaultHiveKey 'C:\Users\Default\NTUSER.DAT' |
|
330 |
+ New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS |
|
331 |
+ |
|
332 |
+ $sids = 'TEMP', '.DEFAULT', 'S-1-5-19', 'S-1-5-20' |
|
333 |
+ foreach ($sid in $sids) { |
|
334 |
+ Copy-RegistryKey -source "HKCU:\Keyboard Layout" -target "HKU:\$sid" |
|
335 |
+ Copy-RegistryKey -source "HKCU:\Control Panel\International" -target "HKU:\$sid\Control Panel" |
|
336 |
+ Copy-RegistryKey -source "HKCU:\Control Panel\Input Method" -target "HKU:\$sid\Control Panel" |
|
337 |
+ } |
|
338 |
+ |
|
339 |
+ Remove-PSDrive HKU |
|
340 |
+ [gc]::collect() |
|
341 |
+ reg unload $defaultHiveKey |
|
342 |
+ } |
|
343 |
+ $result.changed = $true |
|
344 |
+} |
|
345 |
+ |
|
346 |
+Exit-Json $result |
0 | 347 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,116 @@ |
0 |
+#!/usr/bin/python |
|
1 |
+# -*- coding: utf-8 -*- |
|
2 |
+ |
|
3 |
+# (c) 2016, Ansible, inc |
|
4 |
+# |
|
5 |
+# This file is part of Ansible |
|
6 |
+# |
|
7 |
+# Ansible is free software: you can redistribute it and/or modify |
|
8 |
+# it under the terms of the GNU General Public License as published by |
|
9 |
+# the Free Software Foundation, either version 3 of the License, or |
|
10 |
+# (at your option) any later version. |
|
11 |
+# |
|
12 |
+# Ansible is distributed in the hope that it will be useful, |
|
13 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
+# GNU General Public License for more details. |
|
16 |
+# |
|
17 |
+# You should have received a copy of the GNU General Public License |
|
18 |
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
|
19 |
+# |
|
20 |
+ |
|
21 |
+ANSIBLE_METADATA = {'status': ['preview'], |
|
22 |
+ 'supported_by': 'community', |
|
23 |
+ 'version': '1.0'} |
|
24 |
+ |
|
25 |
+DOCUMENTATION = r''' |
|
26 |
+module: win_region |
|
27 |
+version_added: "2.3" |
|
28 |
+short_description: Set the region and format settings |
|
29 |
+description: |
|
30 |
+ - Set the location settings of a Windows Server. |
|
31 |
+ - Set the format settings of a Windows Server. |
|
32 |
+ - Set the unicode language settings of a Windows Server. |
|
33 |
+ - Copy across these settings to the default profile. |
|
34 |
+options: |
|
35 |
+ location: |
|
36 |
+ description: |
|
37 |
+ - The location to set for the current user, see |
|
38 |
+ U(https://msdn.microsoft.com/en-us/library/dd374073.aspx) |
|
39 |
+ for a list of GeoIDs you can use and what location it relates to. |
|
40 |
+ This needs to be set if C(format) or C(unicode_language) is not |
|
41 |
+ set. |
|
42 |
+ required: false |
|
43 |
+ format: |
|
44 |
+ description: |
|
45 |
+ - The language format to set for the current user, see |
|
46 |
+ U(https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx) |
|
47 |
+ for a list of culture names to use. This needs to be set if |
|
48 |
+ C(location) or C(unicode_language) is not set. |
|
49 |
+ required: false |
|
50 |
+ unicode_language: |
|
51 |
+ description: |
|
52 |
+ - The unicode language format to set for all users, see |
|
53 |
+ U(https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx) |
|
54 |
+ for a list of culture names to use. This needs to be set if |
|
55 |
+ C(location) or C(format) is not set. After setting this |
|
56 |
+ value a reboot is required for it to take effect. |
|
57 |
+ required: false |
|
58 |
+ copy_settings: |
|
59 |
+ description: |
|
60 |
+ - This will copy the current format and location values to new user |
|
61 |
+ profiles and the welcome screen. This will only run if |
|
62 |
+ C(location), C(format) or C(unicode_language) has resulted in a |
|
63 |
+ change. If this process runs then it will always result in a |
|
64 |
+ change. |
|
65 |
+ required: false |
|
66 |
+ default: false |
|
67 |
+ choices: ['true', 'false'] |
|
68 |
+author: "Jordan Borean (@jborean93)" |
|
69 |
+''' |
|
70 |
+ |
|
71 |
+EXAMPLES = r''' |
|
72 |
+# Set the region format to English United States |
|
73 |
+- win_region: |
|
74 |
+ format: en-US |
|
75 |
+ |
|
76 |
+# Set the region format to English Australia and copy settings to new profiles |
|
77 |
+- win_region: |
|
78 |
+ format: en-AU |
|
79 |
+ copy_settings: True |
|
80 |
+ |
|
81 |
+# Set the unicode language to English Great Britain |
|
82 |
+- win_region: |
|
83 |
+ unicode_language: en-GB |
|
84 |
+ register: result |
|
85 |
+ |
|
86 |
+- action: win_reboot |
|
87 |
+ when: result.restart_required |
|
88 |
+ |
|
89 |
+# Set the location to United States |
|
90 |
+- win_region: |
|
91 |
+ location: 244 |
|
92 |
+ |
|
93 |
+# Set format, location and unicode to English Australia and copy settings |
|
94 |
+- win_region: |
|
95 |
+ location: 12 |
|
96 |
+ format: en-AU |
|
97 |
+ unicode_language: en-AU |
|
98 |
+ register: result |
|
99 |
+ |
|
100 |
+- action: win_reboot |
|
101 |
+ when: result.restart_required |
|
102 |
+''' |
|
103 |
+ |
|
104 |
+RETURN = r''' |
|
105 |
+changed: |
|
106 |
+ description: Whether anything was changed |
|
107 |
+ returned: always |
|
108 |
+ type: boolean |
|
109 |
+ sample: True |
|
110 |
+restart_required: |
|
111 |
+ description: Whether a reboot is required for the change to take effect |
|
112 |
+ returned: success |
|
113 |
+ type: boolean |
|
114 |
+ sample: True |
|
115 |
+''' |
0 | 2 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,252 @@ |
0 |
+# test code for the win_region module |
|
1 |
+# This file is part of Ansible |
|
2 |
+# |
|
3 |
+# Ansible is free software: you can redistribute it and/or modify |
|
4 |
+# it under the terms of the GNU General Public License as published by |
|
5 |
+# the Free Software Foundation, either version 3 of the License, or |
|
6 |
+# (at your option) any later version. |
|
7 |
+# |
|
8 |
+# Ansible is distributed in the hope that it will be useful, |
|
9 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
+# GNU General Public License for more details. |
|
12 |
+# |
|
13 |
+# You should have received a copy of the GNU General Public License |
|
14 |
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
|
15 |
+ |
|
16 |
+- name: expect failure when only setting copy_settings |
|
17 |
+ win_region: |
|
18 |
+ copy_settings: False |
|
19 |
+ register: actual |
|
20 |
+ failed_when: actual.msg != "An argument for 'format', 'location' or 'unicode_language' needs to be supplied" |
|
21 |
+ |
|
22 |
+- name: expect failure when using invalid geo id for the location |
|
23 |
+ win_region: |
|
24 |
+ location: 111111 |
|
25 |
+ register: actual |
|
26 |
+ failed_when: actual.msg != "The argument location '111111' does not contain a valid Geo ID" |
|
27 |
+ |
|
28 |
+- name: expect failure when using invalid culture for format |
|
29 |
+ win_region: |
|
30 |
+ format: ab-CD |
|
31 |
+ register: actual |
|
32 |
+ failed_when: actual.msg != "The argument format 'ab-CD' does not contain a valid Culture Name" |
|
33 |
+ |
|
34 |
+- name: expect failure when using invalid culture for unicode_language |
|
35 |
+ win_region: |
|
36 |
+ unicode_language: ab-CD |
|
37 |
+ register: actual |
|
38 |
+ failed_when: actual.msg != "The argument unicode_language 'ab-CD' does not contain a valid Culture Name" |
|
39 |
+ |
|
40 |
+- name: set settings all to English Australia before tests for a baseline |
|
41 |
+ win_region: |
|
42 |
+ location: 12 |
|
43 |
+ format: en-AU |
|
44 |
+ unicode_language: en-AU |
|
45 |
+ |
|
46 |
+- name: reboot server to set properties |
|
47 |
+ win_reboot: |
|
48 |
+ |
|
49 |
+- name: check that changing location in check mode works |
|
50 |
+ win_region: |
|
51 |
+ location: 244 |
|
52 |
+ register: check_location |
|
53 |
+ check_mode: yes |
|
54 |
+ |
|
55 |
+- name: get current location value |
|
56 |
+ win_command: powershell (Get-ItemProperty -Path 'HKCU:\Control Panel\International\Geo').Nation |
|
57 |
+ register: actual_location |
|
58 |
+ |
|
59 |
+- name: check assertion about location change in check mode |
|
60 |
+ assert: |
|
61 |
+ that: |
|
62 |
+ - "actual_location.stdout_lines[0] == '12'" # Corresponds to en-AU |
|
63 |
+ - "check_location|changed" |
|
64 |
+ - "check_location.restart_required == False" |
|
65 |
+ |
|
66 |
+- name: set location to United States |
|
67 |
+ win_region: |
|
68 |
+ location: 244 |
|
69 |
+ register: location |
|
70 |
+ |
|
71 |
+- name: get current location value |
|
72 |
+ win_command: powershell (Get-ItemProperty -Path 'HKCU:\Control Panel\International\Geo').Nation |
|
73 |
+ register: actual_location |
|
74 |
+ |
|
75 |
+- name: check assertion about location change |
|
76 |
+ assert: |
|
77 |
+ that: |
|
78 |
+ - "actual_location.stdout_lines[0] == '244'" # Corresponds to en-US |
|
79 |
+ - "location|changed" |
|
80 |
+ - "location.restart_required == False" |
|
81 |
+ |
|
82 |
+- name: set location to United States again |
|
83 |
+ win_region: |
|
84 |
+ location: 244 |
|
85 |
+ register: location_again |
|
86 |
+ |
|
87 |
+- name: check that the result did not change |
|
88 |
+ assert: |
|
89 |
+ that: |
|
90 |
+ - "not location_again|changed" |
|
91 |
+ - "location_again.restart_required == False" |
|
92 |
+ |
|
93 |
+- name: set format to English United States in check mode |
|
94 |
+ win_region: |
|
95 |
+ format: en-US |
|
96 |
+ register: check_format |
|
97 |
+ check_mode: yes |
|
98 |
+ |
|
99 |
+- name: get actual format value from check mode |
|
100 |
+ win_command: powershell (Get-Culture).Name |
|
101 |
+ register: actual_format |
|
102 |
+ |
|
103 |
+- name: check assertion about location change in check mode |
|
104 |
+ assert: |
|
105 |
+ that: |
|
106 |
+ - "actual_format.stdout_lines[0] == 'en-AU'" |
|
107 |
+ - "check_format|changed" |
|
108 |
+ - "check_format.restart_required == False" |
|
109 |
+ |
|
110 |
+- name: set format to English United States |
|
111 |
+ win_region: |
|
112 |
+ format: en-US |
|
113 |
+ register: format |
|
114 |
+ |
|
115 |
+- name: get actual format value |
|
116 |
+ win_command: powershell (Get-Culture).Name |
|
117 |
+ register: actual_format |
|
118 |
+ |
|
119 |
+- name: check assertion about format change |
|
120 |
+ assert: |
|
121 |
+ that: |
|
122 |
+ - "actual_format.stdout_lines[0] == 'en-US'" |
|
123 |
+ - "format|changed" |
|
124 |
+ - "format.restart_required == False" |
|
125 |
+ |
|
126 |
+- name: set format to English United States again |
|
127 |
+ win_region: |
|
128 |
+ format: en-US |
|
129 |
+ register: format_again |
|
130 |
+ |
|
131 |
+- name: check that the result did not change |
|
132 |
+ assert: |
|
133 |
+ that: |
|
134 |
+ - "not format_again|changed" |
|
135 |
+ - "format_again.restart_required == False" |
|
136 |
+ |
|
137 |
+- name: set unicode_language to English United States in check mode |
|
138 |
+ win_region: |
|
139 |
+ unicode_language: en-US |
|
140 |
+ register: check_unicode |
|
141 |
+ check_mode: yes |
|
142 |
+ |
|
143 |
+- name: get actual unicode values |
|
144 |
+ win_command: powershell (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language').Default |
|
145 |
+ register: actual_unicode |
|
146 |
+ |
|
147 |
+- name: check assertion about unicode language change in check mode |
|
148 |
+ assert: |
|
149 |
+ that: |
|
150 |
+ - "actual_unicode.stdout_lines[0] == '0c09'" |
|
151 |
+ - "check_unicode|changed" |
|
152 |
+ - "check_unicode.restart_required == True" |
|
153 |
+ |
|
154 |
+- name: set unicode_language to English United States |
|
155 |
+ win_region: |
|
156 |
+ unicode_language: en-US |
|
157 |
+ register: unicode |
|
158 |
+ |
|
159 |
+- name: reboot the server after changing unicode language |
|
160 |
+ action: win_reboot |
|
161 |
+ when: unicode.restart_required |
|
162 |
+ |
|
163 |
+- name: get actual unicode value |
|
164 |
+ win_command: powershell (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language').Default |
|
165 |
+ register: actual_unicode |
|
166 |
+ |
|
167 |
+- name: check assertion about unicode language change |
|
168 |
+ assert: |
|
169 |
+ that: |
|
170 |
+ - "actual_unicode.stdout_lines[0] == '0409'" # corresponds to en-US |
|
171 |
+ - "unicode|changed" |
|
172 |
+ - "unicode.restart_required == True" |
|
173 |
+ |
|
174 |
+- name: set unicode_language to English United States again |
|
175 |
+ win_region: |
|
176 |
+ unicode_language: en-US |
|
177 |
+ register: unicode_again |
|
178 |
+ |
|
179 |
+- name: check that the result did not change |
|
180 |
+ assert: |
|
181 |
+ that: |
|
182 |
+ - "not unicode_again|changed" |
|
183 |
+ - "unicode_again.restart_required == False" |
|
184 |
+ |
|
185 |
+- name: copy settings when setting to the same format check mode |
|
186 |
+ win_region: |
|
187 |
+ format: en-US |
|
188 |
+ copy_settings: True |
|
189 |
+ register: check_copy_same |
|
190 |
+ check_mode: yes |
|
191 |
+ |
|
192 |
+- name: check that the result did not change in check mode |
|
193 |
+ assert: |
|
194 |
+ that: |
|
195 |
+ - "not check_copy_same|changed" |
|
196 |
+ - "check_copy_same.restart_required == False" |
|
197 |
+ |
|
198 |
+- name: copy settings when setting to the same format |
|
199 |
+ win_region: |
|
200 |
+ format: en-US |
|
201 |
+ copy_settings: True |
|
202 |
+ register: copy_same |
|
203 |
+ |
|
204 |
+- name: check that the result did not change |
|
205 |
+ assert: |
|
206 |
+ that: |
|
207 |
+ - "not copy_same|changed" |
|
208 |
+ - "copy_same.restart_required == False" |
|
209 |
+ |
|
210 |
+- name: copy setting when setting to a different format |
|
211 |
+ win_region: |
|
212 |
+ format: en-GB |
|
213 |
+ copy_settings: True |
|
214 |
+ register: copy |
|
215 |
+ |
|
216 |
+- name: get actual format value after copy_settings |
|
217 |
+ win_command: powershell (Get-Culture).Name |
|
218 |
+ register: actual_copy |
|
219 |
+ |
|
220 |
+- name: get locale name for local service registry hive |
|
221 |
+ 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" |
|
222 |
+ register: actual_local |
|
223 |
+ |
|
224 |
+- name: get locale name for network service registry hive |
|
225 |
+ 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" |
|
226 |
+ register: actual_network |
|
227 |
+ |
|
228 |
+- name: load temp hive |
|
229 |
+ win_command: reg load HKU\TEMP C:\Users\Default\NTUSER.DAT |
|
230 |
+ |
|
231 |
+- name: get locale name for default registry hive |
|
232 |
+ win_command: powershell "New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS | Out-Null; (Get-ItemProperty 'HKU:\TEMP\Control Panel\International').LocaleName" |
|
233 |
+ register: actual_temp |
|
234 |
+ |
|
235 |
+- name: unload temp hive |
|
236 |
+ win_command: reg unload HKU\TEMP |
|
237 |
+ |
|
238 |
+- name: get locale name for default registry hive |
|
239 |
+ win_command: powershell "New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS | Out-Null; (Get-ItemProperty 'HKU:\.DEFAULT\Control Panel\International').LocaleName" |
|
240 |
+ register: actual_default |
|
241 |
+ |
|
242 |
+- name: check assertions about copy setting when setting to a different format |
|
243 |
+ assert: |
|
244 |
+ that: |
|
245 |
+ - "actual_copy.stdout_lines[0] == 'en-GB'" |
|
246 |
+ - "actual_local.stdout_lines[0] == 'en-GB'" |
|
247 |
+ - "actual_network.stdout_lines[0] == 'en-GB'" |
|
248 |
+ - "actual_temp.stdout_lines[0] == 'en-GB'" |
|
249 |
+ - "actual_default.stdout_lines[0] == 'en-GB'" |
|
250 |
+ - "copy|changed" |
|
251 |
+ - "copy.restart_required == False" |