Skip to content

Commit

Permalink
Merge pull request #7 from jordiprats/master
Browse files Browse the repository at this point in the history
timezonename per UTC
  • Loading branch information
jordiprats authored Jul 18, 2017
2 parents 56f4d52 + 4459341 commit 85dbcb9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.1.4

* added support to be able to set timezone by name (for example, UTC)

## 0.1.3

* timedatectl support (CentOS 7)
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class { 'timezone':
}
```

Set UTC:

```
class { 'timezone':
timezonename => 'UTC',
}
```

## Usage

It just sets localtime to the appropriate timezone, it doesn't do much fancy stuff.
Expand All @@ -52,6 +60,7 @@ It just sets localtime to the appropriate timezone, it doesn't do much fancy stu
### timezone
* **region**: region to be used (default: **Europe**)
* **locality**: locality to be used (default: **Andorra**)
* **timezonename**: timezone to set, if it is defined, overrides **region** and **locality**
* **manage_package**: manage package, usually it's called tzdata (default: **true**)
* **package_ensure**: package's ensure (default: **installed**)

Expand Down
21 changes: 18 additions & 3 deletions manifests/config.pp
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
class timezone::config inherits timezone {

if($timezone::timezonename!=undef)
{
$tzctl_command = "timedatectl set-timezone ${timezone::timezonename}"
$tzctl_unless = "timedatectl status | grep \"Time zone: ${timezone::timezonename}\""

$file_ln_tz = "file:///usr/share/zoneinfo/${timezone::timezonename}"
}
else
{
$tzctl_command = "timedatectl set-timezone ${timezone::region}/${timezone::locality}"
$tzctl_unless = "timedatectl status | grep \"Time zone: ${timezone::region}/${timezone::locality}\""

$file_ln_tz = "file:///usr/share/zoneinfo/${timezone::region}/${timezone::locality}"
}

if($timezone::params::timedatectl)
{
exec { 'set timezone - timedatectl':
command => "timedatectl set-timezone ${timezone::region}/${timezone::locality}",
unless => "timedatectl status | grep \"Time zone: ${timezone::region}/${timezone::locality}\"",
command => $tzctl_command,
unless => $tzctl_unless,
path => '/usr/sbin:/usr/bin:/sbin:/bin',
}
}
else
{
file { '/etc/localtime':
source => "file:///usr/share/zoneinfo/${timezone::region}/${timezone::locality}",
source => $file_ln_tz,
links => 'follow',
replace => true,
mode => '0644',
Expand Down
11 changes: 6 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class timezone(
$manage_package = true,
$package_ensure = 'installed',
$region = 'Europe',
$locality = 'Andorra',
) inherits timezone::params {
$manage_package = true,
$package_ensure = 'installed',
$region = 'Europe',
$locality = 'Andorra',
$timezonename = undef,
) inherits timezone::params {

class { '::timezone::install': }
-> class { '::timezone::config': }
Expand Down
6 changes: 3 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "eyp-timezone",
"version": "0.1.3",
"version": "0.1.4",
"author": "eyp",
"summary": "sets timezone",
"license": "Apache-2.0",
"source": "https://github.com/NTTCom-MS/eyp-timezone",
"project_page": null,
"project_page": "https://github.com/NTTCom-MS/eyp-timezone",
"issues_url": "https://github.com/NTTCom-MS/eyp-timezone/issues",
"dependencies": [
{"name":"puppetlabs/stdlib","version_requirement":">= 1.0.0"},
{"name":"puppetlabs/stdlib","version_requirement":">= 1.0.0 < 9.9.9"},
{"name":"eyp/eyplib","version_requirement":">= 0.1.0 < 0.2.0"}
],
"operatingsystem_support": [
Expand Down

0 comments on commit 85dbcb9

Please sign in to comment.