0
0
mirror of https://github.com/saltstack-formulas/timezone-formula.git synced 2024-12-18 06:32:56 +01:00
timezone-formula/timezone/init.sls
Imran Iqbal ff66e5fd10
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`
2020-03-23 20:45:20 +00:00

49 lines
1.5 KiB
Plaintext

# -*- coding: utf-8 -*-
# vim: ft=sls
{#- Get the `tplroot` from `tpldir` #}
{%- 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 }}