From 2e38f80f9e5d6b46c5648e19bcb18b69dbc64762 Mon Sep 17 00:00:00 2001 From: Shachaf92 Date: Mon, 2 Mar 2020 00:02:38 +0200 Subject: [PATCH] win_timezone - Allow for _dstoff timezones (#67892) * win_timezone - Allow for _dstoff timezones * Update win_timezone-Allow-dstoff.yml * Added doc entry for new format Co-authored-by: Jordan Borean --- changelogs/fragments/win_timezone-Allow-dstoff.yml | 3 +++ lib/ansible/modules/windows/win_timezone.ps1 | 10 ++-------- lib/ansible/modules/windows/win_timezone.py | 5 +++++ test/integration/targets/win_timezone/tasks/tests.yml | 11 +++++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/win_timezone-Allow-dstoff.yml diff --git a/changelogs/fragments/win_timezone-Allow-dstoff.yml b/changelogs/fragments/win_timezone-Allow-dstoff.yml new file mode 100644 index 00000000000..3d32fd54066 --- /dev/null +++ b/changelogs/fragments/win_timezone-Allow-dstoff.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - "win_timezone - Allow for _dstoff timezones" diff --git a/lib/ansible/modules/windows/win_timezone.ps1 b/lib/ansible/modules/windows/win_timezone.ps1 index 0f609b1584d..f46a11c3ad3 100644 --- a/lib/ansible/modules/windows/win_timezone.ps1 +++ b/lib/ansible/modules/windows/win_timezone.ps1 @@ -28,18 +28,12 @@ Try { Exit-Json $result "Timezone '$timezone' is already set on this machine" } Else { # Check that timezone is listed as an available timezone to the machine - $tzList = $(tzutil.exe /l) + $tzList = $(tzutil.exe /l).ToLower() If ($LASTEXITCODE -ne 0) { Throw "An error occurred when listing the available timezones." } - $tzExists = $false - ForEach ($tz in $tzList) { - If ( $tz -eq $timezone ) { - $tzExists = $true - break - } - } + $tzExists = $tzList.Contains(($timezone -Replace '_dstoff').ToLower()) if (-not $tzExists) { Fail-Json $result "The specified timezone: $timezone isn't supported on the machine." } diff --git a/lib/ansible/modules/windows/win_timezone.py b/lib/ansible/modules/windows/win_timezone.py index 60849657946..a3b66c9e56f 100644 --- a/lib/ansible/modules/windows/win_timezone.py +++ b/lib/ansible/modules/windows/win_timezone.py @@ -20,6 +20,7 @@ options: description: - Timezone to set to. - 'Example: Central Standard Time' + - To disable Daylight Saving time, add the suffix C(_dstoff) on timezones that support this. type: str required: yes notes: @@ -47,6 +48,10 @@ EXAMPLES = r''' - name: Set timezone to 'Central Standard Time' (GMT-06:00) win_timezone: timezone: Central Standard Time + +- name: Set timezime to Pacific Standard time and disable Daylight Saving time adjustments + win_timezone: + timezone: Pacific Standard Time_dstoff ''' RETURN = r''' diff --git a/test/integration/targets/win_timezone/tasks/tests.yml b/test/integration/targets/win_timezone/tasks/tests.yml index 320edc4e495..da5109f7f5e 100644 --- a/test/integration/targets/win_timezone/tasks/tests.yml +++ b/test/integration/targets/win_timezone/tasks/tests.yml @@ -73,6 +73,17 @@ - central.timezone == 'Central Standard Time' when: in_check_mode +- name: Change timezone to dstoff + win_timezone: + timezone: Eastern Standard Time_dstoff + register: dstoff_result + +- name: Test dstoff timezone + assert: + that: + - dstoff_result is changed + - dstoff_result.timezone == 'Eastern Standard Time_dstoff' + - name: Change timezone to GMT+666 win_timezone: timezone: Dag's Standard Time