Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win_timezone - Allow for _dstoff timezones #67892

Merged
merged 3 commits into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/win_timezone-Allow-dstoff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- "win_timezone - Allow for _dstoff timezones"
10 changes: 2 additions & 8 deletions lib/ansible/modules/windows/win_timezone.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Expand Down
5 changes: 5 additions & 0 deletions lib/ansible/modules/windows/win_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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:
Expand Down Expand Up @@ -47,6 +48,10 @@
- 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'''
Expand Down
11 changes: 11 additions & 0 deletions test/integration/targets/win_timezone/tasks/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down