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

Handle timezone updates on Ubuntu 16.04+ on containers #27546

Merged
merged 2 commits into from
Oct 20, 2017
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
16 changes: 9 additions & 7 deletions lib/ansible/modules/system/timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,15 @@ def __init__(self, module):
# Validate given timezone
if 'name' in self.value:
tzfile = self._verify_timezone()
self.update_timezone = self.module.get_bin_path('cp', required=True)
self.update_timezone += ' %s /etc/localtime' % tzfile
self.update_timezone = ['%s %s /etc/localtime' % (self.module.get_bin_path('cp', required=True), tzfile)]
self.update_hwclock = self.module.get_bin_path('hwclock', required=True)
self.allow_no_file['hwclock'] = True # Since this is only used for get values, file absense does not metter
# Distribution-specific configurations
if self.module.get_bin_path('dpkg-reconfigure') is not None:
# Debian/Ubuntu
self.update_timezone = self.module.get_bin_path('dpkg-reconfigure', required=True)
self.update_timezone += ' --frontend noninteractive tzdata'
# With additional hack for https://bugs.launchpad.net/ubuntu/+source/tzdata/+bug/1554806
self.update_timezone = ['rm -f /etc/localtime', '%s --frontend noninteractive tzdata' %
self.module.get_bin_path('dpkg-reconfigure', required=True)]
Copy link
Contributor

@tmshn tmshn Aug 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the temporary fix, instead of making lists, just inserting the command minimizes the diff and clarifies the point of the hack:

             self.update_timezone      += ' --frontend noninteractive tzdata'
+            # With additional hack for https://bugs.launchpad.net/ubuntu/+source/tzdata/+bug/1554806
+            self.update_timezone       = 'rm -f /etc/localtime && ' + self.update_timezone
             self.conf_files['name']    = '/etc/timezone'

self.conf_files['name'] = '/etc/timezone'
self.allow_no_file['name'] = True
self.conf_files['hwclock'] = '/etc/default/rcS'
Expand All @@ -351,7 +351,7 @@ def __init__(self, module):
else:
# RHEL/CentOS
if self.module.get_bin_path('tzdata-update') is not None:
self.update_timezone = self.module.get_bin_path('tzdata-update', required=True)
self.update_timezone = [self.module.get_bin_path('tzdata-update', required=True)]
self.allow_no_file['name'] = True
# else:
# self.update_timezone = 'cp ...' <- configured above
Expand Down Expand Up @@ -456,7 +456,8 @@ def set_timezone(self, value):
regexp=self.regexps['name'],
value=self.tzline_format % value,
key='name')
self.execute(self.update_timezone)
for cmd in self.update_timezone:
self.execute(cmd)

def set_hwclock(self, value):
if value == 'local':
Expand Down Expand Up @@ -652,7 +653,8 @@ def main():
# Examine if the current state matches planned state
(after, planned) = tz.diff('after', 'planned').values()
if after != planned:
tz.abort('still not desired state, though changes have made')
tz.abort('still not desired state, though changes have made - '
'planned: %s, after: %s' % (str(planned), str(after)))
diff = tz.diff('before', 'after')

changed = (diff['before'] != diff['after'])
Expand Down
4 changes: 4 additions & 0 deletions test/integration/targets/timezone/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
destructive
posix/ci/group1
skip/osx
systemd
15 changes: 15 additions & 0 deletions test/integration/targets/timezone/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: set timezone to Etc/UTC
timezone:
name: Etc/UTC

- name: set timezone to Australia/Brisbane
timezone:
name: Australia/Brisbane
register: timezone_set

- name: ensure timezone changed
assert:
that:
- timezone_set.changed
- timezone_set.diff.after.name == 'Australia/Brisbane'
- timezone_set.diff.before.name == 'Etc/UTC'