Puppet Class: psick::timezone

Defined in:
manifests/timezone.pp

Overview

Class ::psick::timezone Derived from github.com/example42/puppet-timezone

This class manages the System’s timezone

Parameters:

timezone

The timezone to use

timezone_windows

The timezone as needed by tzutil.exe command on Windows

hw_utc

If system clock is set to UTC. Default: false

set_timezone_command

The command to execute to apply the new timezone. Default is automatically set according to OS

[template

The template to use for the timezone file.
Default is autocalculated for each supported OS

Parameters:

  • timezone (String) (defaults to: $::psick::time::timezone)
  • timezone_windows (String) (defaults to: '')
  • hw_utc (Boolean) (defaults to: false)
  • set_timezone_command (String) (defaults to: '')
  • template (String) (defaults to: "psick/timezone/timezone-${::operatingsystem}")


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'manifests/timezone.pp', line 25

class psick::timezone(
  String $timezone             = $::psick::time::timezone,
  String $timezone_windows     = '',
  Boolean $hw_utc              = false,
  String $set_timezone_command = '',
  String $template             = "psick/timezone/timezone-${::operatingsystem}",
  ) {

  case $::osfamily {
    'RedHat' : {
      $redhat_command = $::operatingsystemmajrelease ? {
        /7/     => "timedatectl set-timezone ${timezone}",
        default => 'tzdata-update',
      }
    }
    'Debian' : {
      $debian_command = $::operatingsystemmajrelease ? {
        /(16.04|16.10|17.04|17.10|18.04|18.10)/ => "timedatectl set-timezone ${timezone}",
        /(9)/ => "ln -fs /usr/share/zoneinfo/${timezone} /etc/localtime ; dpkg-reconfigure -f noninteractive tzdata",
        default                                 => 'dpkg-reconfigure -f noninteractive tzdata',
      }
    }
    default: { }
  }

  $real_set_timezone_command = $set_timezone_command ? {
    ''      => $::operatingsystem ? {
      /(?i:RedHat|Centos|Scientific|Fedora|Amazon|Linux)/ => $redhat_command,
      /(?i:Ubuntu|Debian|Mint)/                           => $debian_command,
      /(?i:SLES|OpenSuSE)/                                => "zic -l ${timezone}",
      /(?i:OpenBSD)/                                      => "ln -fs /usr/share/zoneinfo/${timezone} /etc/localtime",
      /(?i:FreeBSD)/                                      => "cp /usr/share/zoneinfo/${timezone} /etc/localtime && adjkerntz -a",
      /(?i:Solaris)/                                      => "rtc -z ${timezone} && rtc -c",
      /(?i:Windows)/                                      => "tzutil.exe /s \"${timezone_windows}\"",
      /(?i:Darwin)/                                       => "systemsetup -settimezone ${timezone}",
    },
    default => $set_timezone_command,
  }

  $config_file = $::operatingsystem ? {
    /(?i:RedHat|Centos|Scientific|Fedora|Amazon|Linux)/ => '/etc/sysconfig/clock',
    /(?i:Ubuntu|Debian|Mint)/                           => '/etc/timezone',
    /(?i:SLES|OpenSuSE)/                                => '/etc/sysconfig/clock',
    /(?i:FreeBSD|OpenBSD|Darwin)/                       => '/etc/timezone-puppet',
    /(?i:Solaris)/                                      => '/etc/default/init',
    /(?i:Windows)/                                      => 'c:\temp\timezone',
    default                                             => '',
  }

  $config_file_group = $::operatingsystem ? {
    /(?i:FreeBSD|OpenBSD|Darwin)/ => 'wheel',
    default                       => 'root',
  }

  if $::virtual != 'docker' and $config_file != '' {
    file { 'timezone':
      ensure  => file,
      path    => $config_file,
      mode    => '0644',
      owner   => 'root',
      group   => $config_file_group,
      content => template($template),
    }
    if $::hardwareisa != 'sparc' and $::kernel != 'SunOS' {
      exec { 'set-timezone':
        command     => $real_set_timezone_command,
        path        => $::path,
        require     => File['timezone'],
        subscribe   => File['timezone'],
        refreshonly => true,
      }
    }
  }
}