timezone module: allow suse linux as target (#36719)

* timezone module: allow suse linux as target

* use with statement for file handling
pull/37454/head
Shinichi TAMURA 7 years ago committed by ansibot
parent a8487feb70
commit 73512eeb78

@ -344,7 +344,7 @@ class NosystemdTimezone(Timezone):
self.regexps['name'] = re.compile(r'^([^\s]+)', re.MULTILINE) self.regexps['name'] = re.compile(r'^([^\s]+)', re.MULTILINE)
self.tzline_format = '%s\n' self.tzline_format = '%s\n'
else: else:
# RHEL/CentOS # RHEL/CentOS/SUSE
if self.module.get_bin_path('tzdata-update') is not None: 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 self.allow_no_file['name'] = True
@ -353,6 +353,17 @@ class NosystemdTimezone(Timezone):
# self.allow_no_file['name'] = False <- this is default behavior # self.allow_no_file['name'] = False <- this is default behavior
self.conf_files['name'] = '/etc/sysconfig/clock' self.conf_files['name'] = '/etc/sysconfig/clock'
self.conf_files['hwclock'] = '/etc/sysconfig/clock' self.conf_files['hwclock'] = '/etc/sysconfig/clock'
# The key for timezone might be `ZONE` or `TIMEZONE`
# (the former is used in RHEL/CentOS and the latter is used in SUSE linux).
# So check the content of /etc/sysconfig/clock and decide which key to use.
with open(self.conf_files['name'], mode='r') as f:
sysconfig_clock = f.read()
if re.search(r'^TIMEZONE\s*=', sysconfig_clock, re.MULTILINE):
# For SUSE
self.regexps['name'] = re.compile(r'^TIMEZONE\s*=\s*"?([^"\s]+)"?', re.MULTILINE)
self.tzline_format = 'TIMEZONE="%s"\n'
else:
# For RHEL/CentOS
self.regexps['name'] = re.compile(r'^ZONE\s*=\s*"?([^"\s]+)"?', re.MULTILINE) self.regexps['name'] = re.compile(r'^ZONE\s*=\s*"?([^"\s]+)"?', re.MULTILINE)
self.tzline_format = 'ZONE="%s"\n' self.tzline_format = 'ZONE="%s"\n'

Loading…
Cancel
Save