Add timezone-ii cookbook to set timezone to UTC
This commit is contained in:
28
cookbooks/timezone-ii/recipes/debian.rb
Normal file
28
cookbooks/timezone-ii/recipes/debian.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# Cookbook Name:: timezone-ii
|
||||
# Recipe:: debian
|
||||
#
|
||||
# Copyright 2010, James Harton <james@sociable.co.nz>
|
||||
# Copyright 2013, Lawrence Leonard Gilbert <larry@L2G.to>
|
||||
#
|
||||
# Apache 2.0 License.
|
||||
#
|
||||
|
||||
# Set timezone for Debian family: Put the timezone string in plain text in
|
||||
# /etc/timezone and then re-run the tzdata configuration to pick it up.
|
||||
|
||||
template "/etc/timezone" do
|
||||
source "timezone.conf.erb"
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode 0644
|
||||
notifies :run, 'bash[dpkg-reconfigure tzdata]'
|
||||
end
|
||||
|
||||
bash 'dpkg-reconfigure tzdata' do
|
||||
user 'root'
|
||||
code "/usr/sbin/dpkg-reconfigure -f noninteractive tzdata"
|
||||
action :nothing
|
||||
end
|
||||
|
||||
# vim:ts=2:sw=2:
|
||||
47
cookbooks/timezone-ii/recipes/default.rb
Normal file
47
cookbooks/timezone-ii/recipes/default.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
#
|
||||
# Cookbook Name:: timezone-ii
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2010, James Harton <james@sociable.co.nz>
|
||||
# Copyright 2013, Lawrence Leonard Gilbert <larry@L2G.to>
|
||||
#
|
||||
# Apache 2.0 License.
|
||||
#
|
||||
|
||||
# Make sure the tzdata database is installed. (Arthur David Olson, the computer
|
||||
# timekeeping field is forever in your debt.)
|
||||
package value_for_platform_family(
|
||||
'gentoo' => 'timezone-data',
|
||||
'default' => 'tzdata'
|
||||
)
|
||||
|
||||
case node.platform_family
|
||||
when 'debian', 'fedora'
|
||||
include_recipe "timezone-ii::#{node.platform_family}"
|
||||
|
||||
else
|
||||
if node.os == "linux"
|
||||
# Load the generic Linux recipe if there's no better known way to change the
|
||||
# timezone. Log a warning (unless this is known to be the best way on a
|
||||
# particular platform).
|
||||
message = "Linux platform '#{node.platform}' is unknown to this recipe; " +
|
||||
"using generic Linux method"
|
||||
log message do
|
||||
level :warn
|
||||
not_if { %w( centos gentoo rhel ).include? node.platform_family }
|
||||
end
|
||||
|
||||
include_recipe 'timezone-ii::linux-generic'
|
||||
|
||||
else
|
||||
message = "Don't know how to configure timezone for " +
|
||||
"'#{node.platform_family}'!"
|
||||
log message do
|
||||
level :error
|
||||
end
|
||||
|
||||
end # if/else node.os
|
||||
|
||||
end # case node.platform_family
|
||||
|
||||
# vim:ts=2:sw=2:
|
||||
17
cookbooks/timezone-ii/recipes/fedora.rb
Normal file
17
cookbooks/timezone-ii/recipes/fedora.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Cookbook Name:: timezone-ii
|
||||
# Recipe:: fedora
|
||||
#
|
||||
# Copyright 2013, Lawrence Leonard Gilbert <larry@L2G.to>
|
||||
#
|
||||
# Apache 2.0 License.
|
||||
#
|
||||
|
||||
# Set timezone for Fedora by using its timedatectl utility.
|
||||
|
||||
bash 'timedatectl set-timezone' do
|
||||
user 'root'
|
||||
code "/usr/bin/timedatectl --no-ask-password set-timezone #{node.tz}"
|
||||
end
|
||||
|
||||
# vim:ts=2:sw=2:
|
||||
46
cookbooks/timezone-ii/recipes/linux-generic.rb
Normal file
46
cookbooks/timezone-ii/recipes/linux-generic.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
#
|
||||
# Cookbook Name:: timezone-ii
|
||||
# Recipe:: linux-generic
|
||||
#
|
||||
# Copyright 2013, Lawrence Leonard Gilbert <larry@L2G.to>
|
||||
#
|
||||
# Apache 2.0 License.
|
||||
#
|
||||
|
||||
# Generic timezone-changing method for Linux that should work for any distro
|
||||
# without a platform-specific method.
|
||||
|
||||
timezone_data_file = File.join(node.timezone.tzdata_dir, node.tz)
|
||||
localtime_path = node.timezone.localtime_path
|
||||
|
||||
ruby_block "confirm timezone" do
|
||||
block {
|
||||
unless File.exist?(timezone_data_file)
|
||||
raise "Can't find #{timezone_data_file}!"
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
if node.timezone.use_symlink
|
||||
link localtime_path do
|
||||
to timezone_data_file
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode 0644
|
||||
end
|
||||
|
||||
else
|
||||
file localtime_path do
|
||||
content File.open(timezone_data_file, 'rb').read
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode 0644
|
||||
not_if {
|
||||
File.symlink?(localtime_path) and
|
||||
Chef::Log.error "You must remove symbolic link at #{localtime_path}" +
|
||||
" or set attribute ['timezone']['use_symlink']=true"
|
||||
}
|
||||
end
|
||||
end # if/else node.timezone.use_symlink
|
||||
|
||||
# vim:ts=2:sw=2:
|
||||
Reference in New Issue
Block a user