mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
timezone module: allow suse linux as target (#36719)
* timezone module: allow suse linux as target * use with statement for file handling
This commit is contained in:
parent
a8487feb70
commit
73512eeb78
1 changed files with 14 additions and 3 deletions
|
@ -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,8 +353,19 @@ 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'
|
||||||
self.regexps['name'] = re.compile(r'^ZONE\s*=\s*"?([^"\s]+)"?', re.MULTILINE)
|
# The key for timezone might be `ZONE` or `TIMEZONE`
|
||||||
self.tzline_format = 'ZONE="%s"\n'
|
# (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.tzline_format = 'ZONE="%s"\n'
|
||||||
|
|
||||||
def _allow_ioerror(self, err, key):
|
def _allow_ioerror(self, err, key):
|
||||||
# In some cases, even if the target file does not exist,
|
# In some cases, even if the target file does not exist,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue