From ff66e5fd10c06da5dbe2ae2320fd8f2eddc459f7 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Mon, 23 Mar 2020 11:36:45 +0000 Subject: [PATCH] fix: ensure formula works across all platforms Before: * https://travis-ci.org/github/myii/timezone-formula/builds/665820454 After: * https://travis-ci.org/github/myii/timezone-formula/builds/665975767 * https://travis-ci.org/github/myii/timezone-formula/builds/666039725 (all platforms) Includes: * fix(init.sls): ensure `dbus` is available for `timezone.system` state * fix(init.sls): use symlink to `UTC` if `localtime` does not exist * fix(init.sls): force the creation of the initial symlink * fix: avoid running `dbus` service on `ubuntu-16.04`, `amazonlinux-1` & `centos-6` --- timezone/defaults.yaml | 5 ++++ timezone/init.sls | 53 +++++++++++++++++++++++++++------------ timezone/osfamilymap.yaml | 26 ++++++++++++++++--- timezone/osfingermap.yaml | 40 ++++++++++++++++++++++++++++- timezone/osmap.yaml | 22 +++++++++++++++- 5 files changed, 124 insertions(+), 22 deletions(-) diff --git a/timezone/defaults.yaml b/timezone/defaults.yaml index 2574215..82afac8 100644 --- a/timezone/defaults.yaml +++ b/timezone/defaults.yaml @@ -3,8 +3,13 @@ --- timezone: name: Europe/Berlin + tz_UTC: Etc/UTC utc: true path_localtime: /etc/localtime path_zoneinfo: /usr/share/zoneinfo/ pkg: name: tzdata + dbus: + pkg: dbus + service: dbus + run_service: true diff --git a/timezone/init.sls b/timezone/init.sls index 3372550..c508387 100644 --- a/timezone/init.sls +++ b/timezone/init.sls @@ -5,23 +5,44 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import timezone with context %} +{%- if grains.os not in ('MacOS', 'Windows') %} +timezone_packages: + {#- Work around bug in Salt for certain platforms where symlink isn't available #} + {%- if not salt['file.file_exists'](timezone.path_localtime) %} + file.symlink: + - name: {{ timezone.path_localtime }} + - target: {{ timezone.path_zoneinfo }}{{ timezone.tz_UTC }} + - force: true + - require_in: + # Required for unattended installation of the timezone package + - pkg: timezone_packages + # Required for timezone comparison (symlink must be present for checking the current timezone) + - timezone: timezone_setting + {%- endif %} + pkg.installed: + - name: {{ timezone.pkg.name }} + - require_in: + # Required for timezone comparison (current and proposed) + - timezone: timezone_setting + +dbus_for_timezone: + pkg.installed: + - name: {{ timezone.dbus.pkg }} + - require_in: + - timezone: timezone_setting + {%- if timezone.dbus.run_service %} + service.running: + - name: {{ timezone.dbus.service }} + - enable: true + - require: + - pkg: dbus_for_timezone + - require_in: + # `dbus` is required for running `timedatectl` + - timezone: timezone_setting + {%- endif %} +{%- endif %} + timezone_setting: timezone.system: - name: {{ timezone.name }} - utc: {{ timezone.utc }} - -{%- if grains.os not in ('MacOS', 'Windows') %} - -timezone_packages: - pkg.installed: - - name: {{ timezone.pkg.name }} - -timezone_symlink: - file.symlink: - - name: {{ timezone.path_localtime }} - - target: {{ timezone.path_zoneinfo }}{{ timezone.name }} - - force: true - - require: - - pkg: {{ timezone.pkg.name }} - -{%- endif %} diff --git a/timezone/osfamilymap.yaml b/timezone/osfamilymap.yaml index 96a9c0f..fa089de 100644 --- a/timezone/osfamilymap.yaml +++ b/timezone/osfamilymap.yaml @@ -10,16 +10,34 @@ # you will need to provide at least an empty dict in this file, e.g. # osfamilymap: {} --- +Debian: {} + +RedHat: {} + Suse: pkg: name: timezone - -FreeBSD: - pkg: - name: zoneinfo + dbus: + pkg: dbus-1 Gentoo: pkg: name: sys-libs/timezone-data +Arch: {} + +Alpine: {} + +FreeBSD: + pkg: + name: zoneinfo + +OpenBSD: + pkg: + name: zoneinfo + +Solaris: {} + +Windows: {} + MacOS: {} diff --git a/timezone/osfingermap.yaml b/timezone/osfingermap.yaml index 221bedf..51c5e92 100644 --- a/timezone/osfingermap.yaml +++ b/timezone/osfingermap.yaml @@ -10,4 +10,42 @@ # you will need to provide at least an empty dict in this file, e.g. # osfingermap: {} --- -osfingermap: {} +# os: Debian +Debian-10: {} +Debian-9: {} +Debian-8: {} + +# os: Ubuntu +Ubuntu-18.04: {} +Ubuntu-16.04: + dbus: + run_service: false + +# os: Fedora +Fedora-31: {} +Fedora-30: {} + +# os: CentOS +CentOS Linux-8: {} +CentOS Linux-7: {} +CentOS-6: + dbus: + run_service: false + +# os: Amazon +Amazon Linux-2: {} +Amazon Linux AMI-2018: + dbus: + run_service: false + +# os: SUSE +Leap-15: {} + +# os: FreeBSD +FreeBSD-12: {} + +# os: Windows +Windows-8.1: {} + +# os: Gentoo +Gentoo-2: {} diff --git a/timezone/osmap.yaml b/timezone/osmap.yaml index 2ec94b4..de11a67 100644 --- a/timezone/osmap.yaml +++ b/timezone/osmap.yaml @@ -10,4 +10,24 @@ # you will need to provide at least an empty dict in this file, e.g. # osmap: {} --- -osmap: {} +# os_family: Debian +Ubuntu: {} +Raspbian: {} + +# os_family: RedHat +Fedora: {} +CentOS: {} +Amazon: {} + +# os_family: Suse +SUSE: {} +openSUSE: {} + +# os_family: Gentoo +Funtoo: {} + +# os_family: Arch +Manjaro: {} + +# os_family: Solaris +SmartOS: {}