Vendor the external cookbooks
Knife-Zero doesn't include Berkshelf support, so vendoring everything in the repo is convenient again
This commit is contained in:
27
cookbooks/timezone_iii/recipes/amazon.rb
Normal file
27
cookbooks/timezone_iii/recipes/amazon.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# Cookbook:: timezone_iii
|
||||
# Recipe:: amazon
|
||||
#
|
||||
# Copyright:: 2017, Corey Hemminger
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Amazon recommends editing /etc/sysconfig/clock as in the rhel recipe, but then
|
||||
# creating a link for /etc/localtime. It doesn't have a tzdata-update command
|
||||
# like the other flavors of RHEL.
|
||||
#
|
||||
# Source: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html
|
||||
# (as of 2014-12-18)
|
||||
|
||||
include_recipe 'timezone_iii::linux_generic'
|
||||
include_recipe 'timezone_iii::rhel'
|
||||
61
cookbooks/timezone_iii/recipes/debian.rb
Normal file
61
cookbooks/timezone_iii/recipes/debian.rb
Normal file
@@ -0,0 +1,61 @@
|
||||
#
|
||||
# Cookbook:: timezone_iii
|
||||
# Recipe:: debian
|
||||
#
|
||||
# Copyright:: 2017, Corey Hemminger
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the 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.
|
||||
|
||||
TIMEZONE_FILE = '/etc/timezone'.freeze
|
||||
|
||||
if File.file?('/etc/localtime') then
|
||||
bash 'check-localtime' do
|
||||
user 'root'
|
||||
cwd '/tmp'
|
||||
code <<-EOH
|
||||
ls -la /etc/localtime >> /tmp/check.txt
|
||||
if grep node['timezone_iii']['timezone'] /tmp/check.txt ; then
|
||||
echo "Nothing to do!!!"
|
||||
else
|
||||
rm /etc/localtime
|
||||
fi
|
||||
rm /tmp/check.txt
|
||||
EOH
|
||||
end
|
||||
end
|
||||
|
||||
template TIMEZONE_FILE do
|
||||
source 'timezone.conf.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
notifies :run, 'execute[dpkg-reconfigure-tzdata]'
|
||||
end
|
||||
|
||||
execute 'dpkg-reconfigure-tzdata' do
|
||||
command '/usr/sbin/dpkg-reconfigure -f noninteractive tzdata'
|
||||
action :nothing
|
||||
end
|
||||
|
||||
# Certain values get normalized by dpkg-reconfigure, causing this recipe to try
|
||||
# to rewrite the file over and over. This raises a red flag in such a case.
|
||||
log 'if-unexpected-timezone-change' do
|
||||
message "dpkg-reconfigure is amending the value #{node['timezone_iii']['timezone'].inspect} in #{TIMEZONE_FILE}"
|
||||
level :warn
|
||||
not_if { ::File.read(TIMEZONE_FILE).chomp == node['timezone_iii']['timezone'] }
|
||||
action :nothing
|
||||
subscribes :write, 'execute[dpkg-reconfigure-tzdata]', :immediately
|
||||
end
|
||||
46
cookbooks/timezone_iii/recipes/default.rb
Normal file
46
cookbooks/timezone_iii/recipes/default.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
#
|
||||
# Cookbook:: timezone_iii
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright:: 2017, Corey Hemminger
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
case node['os']
|
||||
when 'linux'
|
||||
package value_for_platform_family(
|
||||
gentoo: 'timezone-data',
|
||||
default: 'tzdata'
|
||||
)
|
||||
case node['platform_family']
|
||||
when 'rhel', 'fedora'
|
||||
include_recipe node['platform_version'].split('.')[0].to_i >= 7 ? 'timezone_iii::rhel7' : 'timezone_iii::rhel'
|
||||
when 'debian', 'pld', 'amazon'
|
||||
include_recipe "timezone_iii::#{node['platform_family']}"
|
||||
else
|
||||
# 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 amazon).include? node['platform_family'] }
|
||||
only_if { node['os'] == 'linux' }
|
||||
end
|
||||
include_recipe 'timezone_iii::linux_generic'
|
||||
end
|
||||
when 'windows'
|
||||
include_recipe 'timezone_iii::windows'
|
||||
else
|
||||
raise 'OS Unsuported'
|
||||
end
|
||||
49
cookbooks/timezone_iii/recipes/linux_generic.rb
Normal file
49
cookbooks/timezone_iii/recipes/linux_generic.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
#
|
||||
# Cookbook:: timezone_iii
|
||||
# Recipe:: linux_generic
|
||||
#
|
||||
# Copyright:: 2017, Corey Hemminger
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the 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_iii']['tzdata_dir'], node['timezone_iii']['timezone'])
|
||||
localtime_path = node['timezone_iii']['localtime_path']
|
||||
|
||||
ruby_block 'confirm timezone' do
|
||||
block do
|
||||
unless File.exist?(timezone_data_file)
|
||||
raise "Can't find #{timezone_data_file}!"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if node['timezone_iii']['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) && Chef::Log.error("You must remove symbolic link at #{localtime_path} or set attribute ['timezone']['use_symlink'] = true") }
|
||||
end
|
||||
end
|
||||
32
cookbooks/timezone_iii/recipes/pld.rb
Normal file
32
cookbooks/timezone_iii/recipes/pld.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# Cookbook:: timezone_iii
|
||||
# Recipe:: pld
|
||||
#
|
||||
# Copyright:: 2017, Corey Hemminger
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Set timezone for PLD family: Put the timezone string in plain text in
|
||||
# /etc/sysconfig/timezone and then re-run the timezone service to pick it up.
|
||||
|
||||
template '/etc/sysconfig/timezone' do
|
||||
source 'pld/timezone.conf.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
notifies :reload, 'service[timezone]'
|
||||
end
|
||||
|
||||
service 'timezone' do
|
||||
action :nothing
|
||||
end
|
||||
38
cookbooks/timezone_iii/recipes/rhel.rb
Normal file
38
cookbooks/timezone_iii/recipes/rhel.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
#
|
||||
# Cookbook:: timezone_iii
|
||||
# Recipe:: rhel
|
||||
#
|
||||
# Copyright:: 2017, Corey Hemminger
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This recipe sets the timezone on EL 6 and older (RedHat Enterprise Linux,
|
||||
# CentOS, etc.)
|
||||
#
|
||||
# If it is being run on EL 7 or newer, the recipe will be skipped and
|
||||
# the "rhel7" recipe will be included instead.
|
||||
|
||||
template '/etc/sysconfig/clock' do
|
||||
source 'rhel/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
|
||||
35
cookbooks/timezone_iii/recipes/rhel7.rb
Normal file
35
cookbooks/timezone_iii/recipes/rhel7.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
#
|
||||
# Cookbook:: timezone_iii
|
||||
# Recipe:: amazon
|
||||
#
|
||||
# Copyright:: 2017, Corey Hemminger
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This sets the timezone on EL 7 distributions (e.g. RedHat and CentOS)
|
||||
execute "timedatectl --no-ask-password set-timezone #{node['timezone_iii']['timezone']}"
|
||||
|
||||
template '/etc/sysconfig/clock' do
|
||||
source 'rhel/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
|
||||
24
cookbooks/timezone_iii/recipes/windows.rb
Normal file
24
cookbooks/timezone_iii/recipes/windows.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# Cookbook:: timezone_iii
|
||||
# Recipe:: amazon
|
||||
#
|
||||
# Copyright:: 2017, Corey Hemminger
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
powershell_script 'set windows timezone' do
|
||||
code <<-EOH
|
||||
tzutil.exe /s "#{node['timezone_iii']['timezone']}"
|
||||
EOH
|
||||
not_if { shell_out('tzutil.exe /g').stdout.include?(node['timezone_iii']['timezone']) }
|
||||
end
|
||||
Reference in New Issue
Block a user