mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* add alpine linux as NosystemdTimezone
* syntax error fix and more self variables, so it works now...
* use timezone name instead of timezone path for setup-timezone command
* alpine linux zoneinfo links to /etc/zoneinfo instead of /usr/share/zoneinfo, so correct re.search() pattern
* add changelog fragment
* add gentoo linux support
* Update 1722_timezone.yml
* refactor code
(cherry picked from commit 9aef0ed17e
)
Co-authored-by: Anatoly Pugachev <matorola@gmail.com>
This commit is contained in:
parent
6831aa5501
commit
983b292399
2 changed files with 14 additions and 5 deletions
2
changelogs/fragments/1722_timezone.yml
Normal file
2
changelogs/fragments/1722_timezone.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- timezone - add Gentoo and Alpine Linux support (https://github.com/ansible-collections/community.general/issues/781).
|
|
@ -355,20 +355,26 @@ class NosystemdTimezone(Timezone):
|
||||||
# Validate given timezone
|
# Validate given timezone
|
||||||
if 'name' in self.value:
|
if 'name' in self.value:
|
||||||
tzfile = self._verify_timezone()
|
tzfile = self._verify_timezone()
|
||||||
|
planned_tz = self.value['name']['planned']
|
||||||
# `--remove-destination` is needed if /etc/localtime is a symlink so
|
# `--remove-destination` is needed if /etc/localtime is a symlink so
|
||||||
# that it overwrites it instead of following it.
|
# that it overwrites it instead of following it.
|
||||||
self.update_timezone = ['%s --remove-destination %s /etc/localtime' % (self.module.get_bin_path('cp', required=True), tzfile)]
|
self.update_timezone = ['%s --remove-destination %s /etc/localtime' % (self.module.get_bin_path('cp', required=True), tzfile)]
|
||||||
self.update_hwclock = self.module.get_bin_path('hwclock', required=True)
|
self.update_hwclock = self.module.get_bin_path('hwclock', required=True)
|
||||||
|
distribution = get_distribution()
|
||||||
|
self.conf_files['name'] = '/etc/timezone'
|
||||||
|
self.regexps['name'] = re.compile(r'^([^\s]+)', re.MULTILINE)
|
||||||
|
self.tzline_format = '%s\n'
|
||||||
# Distribution-specific configurations
|
# Distribution-specific configurations
|
||||||
if self.module.get_bin_path('dpkg-reconfigure') is not None:
|
if self.module.get_bin_path('dpkg-reconfigure') is not None:
|
||||||
# Debian/Ubuntu
|
# Debian/Ubuntu
|
||||||
if 'name' in self.value:
|
if 'name' in self.value:
|
||||||
self.update_timezone = ['%s -sf %s /etc/localtime' % (self.module.get_bin_path('ln', required=True), tzfile),
|
self.update_timezone = ['%s -sf %s /etc/localtime' % (self.module.get_bin_path('ln', required=True), tzfile),
|
||||||
'%s --frontend noninteractive tzdata' % self.module.get_bin_path('dpkg-reconfigure', required=True)]
|
'%s --frontend noninteractive tzdata' % self.module.get_bin_path('dpkg-reconfigure', required=True)]
|
||||||
self.conf_files['name'] = '/etc/timezone'
|
|
||||||
self.conf_files['hwclock'] = '/etc/default/rcS'
|
self.conf_files['hwclock'] = '/etc/default/rcS'
|
||||||
self.regexps['name'] = re.compile(r'^([^\s]+)', re.MULTILINE)
|
elif distribution == 'Alpine' or distribution == 'Gentoo':
|
||||||
self.tzline_format = '%s\n'
|
self.conf_files['hwclock'] = '/etc/conf.d/hwclock'
|
||||||
|
if distribution == 'Alpine':
|
||||||
|
self.update_timezone = ['%s -z %s' % (self.module.get_bin_path('setup-timezone', required=True), planned_tz)]
|
||||||
else:
|
else:
|
||||||
# RHEL/CentOS/SUSE
|
# 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:
|
||||||
|
@ -386,7 +392,6 @@ class NosystemdTimezone(Timezone):
|
||||||
except IOError as err:
|
except IOError as err:
|
||||||
if self._allow_ioerror(err, 'name'):
|
if self._allow_ioerror(err, 'name'):
|
||||||
# If the config file doesn't exist detect the distribution and set regexps.
|
# If the config file doesn't exist detect the distribution and set regexps.
|
||||||
distribution = get_distribution()
|
|
||||||
if distribution == 'SuSE':
|
if distribution == 'SuSE':
|
||||||
# For SUSE
|
# For SUSE
|
||||||
self.regexps['name'] = self.dist_regexps['SuSE']
|
self.regexps['name'] = self.dist_regexps['SuSE']
|
||||||
|
@ -536,7 +541,9 @@ class NosystemdTimezone(Timezone):
|
||||||
# to other zone files, so it's hard to get which TZ is actually set
|
# to other zone files, so it's hard to get which TZ is actually set
|
||||||
# if we follow the symlink.
|
# if we follow the symlink.
|
||||||
path = os.readlink('/etc/localtime')
|
path = os.readlink('/etc/localtime')
|
||||||
linktz = re.search(r'/usr/share/zoneinfo/(.*)', path, re.MULTILINE)
|
# most linuxes has it in /usr/share/zoneinfo
|
||||||
|
# alpine linux links under /etc/zoneinfo
|
||||||
|
linktz = re.search(r'(?:/(?:usr/share|etc)/zoneinfo/)(.*)', path, re.MULTILINE)
|
||||||
if linktz:
|
if linktz:
|
||||||
valuelink = linktz.group(1)
|
valuelink = linktz.group(1)
|
||||||
if valuelink != planned:
|
if valuelink != planned:
|
||||||
|
|
Loading…
Reference in a new issue