Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chef-client 13.0.113 compatability fixes #42

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -9,7 +9,6 @@ Berksfile.lock
/cookbooks

# Bundler
Gemfile.lock
bin/*
.bundle/*

Expand Down
8 changes: 4 additions & 4 deletions attributes/default.rb
@@ -1,15 +1,15 @@
# Use universal time if no other timezone is specified
default.tz = value_for_platform_family(
default['tz'] = value_for_platform_family(
'debian' => 'Etc/UTC',
'default' => 'UTC'
)

# Path to tzdata directory
default.timezone.tzdata_dir = '/usr/share/zoneinfo'
default['timezone']['tzdata_dir'] = '/usr/share/zoneinfo'

# Path to file used by kernel for local timezone's data
default.timezone.localtime_path = '/etc/localtime'
default['timezone']['localtime_path'] = '/etc/localtime'

# Whether to use a symlink to tzdata (instead of copying).
# Used only in the linux-default recipe.
default.timezone.use_symlink = false
default['timezone']['use_symlink'] = false
2 changes: 1 addition & 1 deletion files/default/tests/minitest/default_test.rb
Expand Up @@ -5,7 +5,7 @@ class TimezoneIiSpec < MiniTest::Chef::Spec
describe_recipe 'timezone-ii::default' do

it 'updates the timezone' do
IO.read('/etc/localtime').must_equal IO.read("/usr/share/zoneinfo/#{node[:tz]}")
IO.read('/etc/localtime').must_equal IO.read("/usr/share/zoneinfo/#{node['tz']}")
end

end
Expand Down
34 changes: 17 additions & 17 deletions metadata.rb
@@ -1,19 +1,19 @@
name "timezone-ii"
maintainer "Lawrence Leonard Gilbert"
maintainer_email "larry@L2G.to"
license "Apache 2.0"
description "Configure the system timezone on *ix systems"
version "0.2.9992"
name 'timezone-ii'
maintainer 'Lawrence Leonard Gilbert'
maintainer_email 'larry@L2G.to'
license 'Apache 2.0'
description' Configure the system timezone on *ix systems'
version '0.2.0'

replaces "timezone"
replaces 'timezone'

# These are platform versions where this cookbook has been tested at some point
# in time
supports "amazon"
supports "centos"
supports "debian"
supports "fedora"
supports "gentoo"
supports "ubuntu"
supports "pld"
supports "redhat"
# These are platform versions where this cookbook has been tested at some point in time

%w(amazon centos debian fedora gentoo ubuntu pld redhat).each do |os|
supports os
end

source_url 'https://github.com/L2G/timezone-ii' if defined?(:source_url)
issues_url 'https://github.com/L2G/timezone-ii/issues' if defined?(:issues_url)

chef_version '>= 12.1' if respond_to?(:chef_version)
31 changes: 15 additions & 16 deletions recipes/default.rb
Expand Up @@ -15,37 +15,36 @@
'default' => 'tzdata'
)

case node.platform_family
when 'rhel'
include_recipe value_for_platform(
'amazon' => { 'default' => 'timezone-ii::amazon' },
'default' => 'timezone-ii::rhel'
)
case node['platform_family']
when 'rhel', 'fedora'
if node['platform_version'].split('.')[0].to_i >= 7
include_recipe 'timezone-ii::rhel7'
else
include_recipe 'timezone-ii::rhel'
end

when 'debian', 'fedora', 'pld'
include_recipe "timezone-ii::#{node.platform_family}"
when 'debian', 'pld', 'amazon'
include_recipe "timezone-ii::#{node['platform_family']}"

else
if node.os == "linux"
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; " +
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 }
not_if { %w(centos gentoo rhel amazon).include? node['platform_family'] }
end

include_recipe 'timezone-ii::linux-generic'

else
message = "Don't know how to configure timezone for " +
"'#{node.platform_family}'!"
"'#{node['platform_family']}'!"
log message do
level :error
end

end # if/else node.os

end # case node.platform_family
end
end
11 changes: 0 additions & 11 deletions recipes/fedora.rb

This file was deleted.

8 changes: 4 additions & 4 deletions recipes/linux-generic.rb
Expand Up @@ -10,8 +10,8 @@
# 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
timezone_data_file = File.join(node['timezone']['tzdata_dir'], node['tz'])
localtime_path = node['timezone']['localtime_path']

ruby_block "confirm timezone" do
block {
Expand All @@ -21,7 +21,7 @@
}
end

if node.timezone.use_symlink
if node['timezone']['use_symlink']
link localtime_path do
to timezone_data_file
owner 'root'
Expand All @@ -41,4 +41,4 @@
" or set attribute ['timezone']['use_symlink']=true"
}
end
end # if/else node.timezone.use_symlink
end
31 changes: 12 additions & 19 deletions recipes/rhel.rb
Expand Up @@ -14,24 +14,17 @@
# If it is being run on EL 7 or newer, the recipe will be skipped and
# the "rhel7" recipe will be included instead.

el_version = node[:platform_version].split('.')[0].to_i

if el_version >= 7
include_recipe 'timezone-ii::rhel7'

else
template '/etc/sysconfig/clock' do
source 'clock.erb'
owner 'root'
group 'root'
mode 0644
notifies :run, 'execute[tzdata-update]'
end
template '/etc/sysconfig/clock' do
source 'clock.erb'
owner 'root'
group 'root'
mode 0644
notifies :run, 'execute[tzdata-update]'
end

execute 'tzdata-update' do
command '/usr/sbin/tzdata-update'
action :nothing
# Amazon Linux doesn't have this command!
only_if { ::File.executable?('/usr/sbin/tzdata-update') }
end
execute 'tzdata-update' do
command '/usr/sbin/tzdata-update'
action :nothing
# Amazon Linux doesn't have this command!
only_if { ::File.executable?('/usr/sbin/tzdata-update') }
end
17 changes: 16 additions & 1 deletion recipes/rhel7.rb
Expand Up @@ -8,4 +8,19 @@
#

# This sets the timezone on EL 7 distributions (e.g. RedHat and CentOS)
execute "timedatectl --no-ask-password set-timezone #{node[:tz]}"
execute "timedatectl --no-ask-password set-timezone #{node['tz']}"

template '/etc/sysconfig/clock' do
source 'clock.erb'
owner 'root'
group 'root'
mode 0644
notifies :run, 'execute[tzdata-update]'
end

execute 'tzdata-update' do
command '/usr/sbin/tzdata-update'
action :nothing
# Amazon Linux doesn't have this command!
only_if { ::File.executable?('/usr/sbin/tzdata-update') }
end
16 changes: 8 additions & 8 deletions spec/attributes_spec.rb
Expand Up @@ -6,20 +6,20 @@
ChefSpec::SoloRunner.new(platform: 'debian', version: '7.4').converge('timezone-ii')
end

specify { expect(chef_run.node[:tz]) .to eq 'Etc/UTC' }
specify { expect(chef_run.node[:timezone][:tzdata_dir]) .to eq '/usr/share/zoneinfo' }
specify { expect(chef_run.node[:timezone][:localtime_path]).to eq '/etc/localtime' }
specify { expect(chef_run.node[:timezone][:use_symlink]) .to be_falsey }
specify { expect(chef_run.node['tz']).to eq 'Etc/UTC' }
specify { expect(chef_run.node['timezone']['tzdata_dir']).to eq '/usr/share/zoneinfo' }
specify { expect(chef_run.node['timezone']['localtime_path']).to eq '/etc/localtime' }
specify { expect(chef_run.node['timezone']['use_symlink']).to be_falsey }
end

context 'on non-Debian' do
let(:chef_run) do
ChefSpec::SoloRunner.new.converge('timezone-ii')
end

specify { expect(chef_run.node[:tz]) .to eq 'UTC' }
specify { expect(chef_run.node[:timezone][:tzdata_dir]) .to eq '/usr/share/zoneinfo' }
specify { expect(chef_run.node[:timezone][:localtime_path]).to eq '/etc/localtime' }
specify { expect(chef_run.node[:timezone][:use_symlink]) .to be_falsey }
specify { expect(chef_run.node['tz']).to eq 'UTC' }
specify { expect(chef_run.node['timezone']['tzdata_dir']).to eq '/usr/share/zoneinfo' }
specify { expect(chef_run.node['timezone']['localtime_path']).to eq '/etc/localtime' }
specify { expect(chef_run.node['timezone']['use_symlink']).to be_falsey }
end
end
2 changes: 1 addition & 1 deletion templates/amazon/clock.erb
@@ -1 +1 @@
ZONE="<%= node[:tz] %>"
ZONE="<%= node['tz'] %>"
2 changes: 1 addition & 1 deletion templates/centos/clock.erb
@@ -1 +1 @@
ZONE="<%= node[:tz] %>"
ZONE="<%= node['tz'] %>"
2 changes: 1 addition & 1 deletion templates/default/timezone.conf.erb
@@ -1 +1 @@
<%= node[:tz] %>
<%= node['tz'] %>
2 changes: 1 addition & 1 deletion templates/pld/timezone.conf.erb
Expand Up @@ -7,4 +7,4 @@ ZONE_INFO_DIR="<%= node['timezone']['tzdata_dir'] %>"
ZONE_INFO_SCHEME="posix"

# Name of the time zone for your system.
TIMEZONE="<%= node[:tz] %>"
TIMEZONE="<%= node['tz'] %>"
2 changes: 1 addition & 1 deletion templates/redhat/clock.erb
@@ -1 +1 @@
ZONE="<%= node[:tz] %>"
ZONE="<%= node['tz'] %>"