5 # Copyright:: 2010, OpenStreetMap Foundation
 
   7 # Licensed under the Apache License, Version 2.0 (the "License");
 
   8 # you may not use this file except in compliance with the License.
 
   9 # You may obtain a copy of the License at
 
  11 #     https://www.apache.org/licenses/LICENSE-2.0
 
  13 # Unless required by applicable law or agreed to in writing, software
 
  14 # distributed under the License is distributed on an "AS IS" BASIS,
 
  15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  16 # See the License for the specific language governing permissions and
 
  17 # limitations under the License.
 
  20 cache_dir = Chef::Config[:file_cache_path]
 
  22 chef_version = node[:chef][:client][:version]
 
  24 chef_platform = if platform?("debian")
 
  36 os_release = if platform?("debian") && node[:lsb][:release].to_f > 11
 
  42 # Chef is currently not available for Debian 11 on arm64.
 
  43 if chef_platform == "debian" && os_release == 11 && chef_arch == "arm64"
 
  44   chef_platform = "ubuntu"
 
  48 chef_package = "chef_#{chef_version}-1_#{chef_arch}.deb"
 
  50 directory "/var/cache/chef" do
 
  55 Dir.glob("#{cache_dir}/chef_*.deb").each do |deb|
 
  56   next if deb == "#{cache_dir}/#{chef_package}"
 
  64 remote_file "#{cache_dir}/#{chef_package}" do
 
  65   source "https://packages.chef.io/files/stable/chef/#{chef_version}/#{chef_platform}/#{os_release}/#{chef_package}"
 
  73 dpkg_package "chef" do
 
  74   source "#{cache_dir}/#{chef_package}"
 
  75   version "#{chef_version}-1"
 
  78 directory "/etc/chef" do
 
  84 template "/etc/chef/client.rb" do
 
  85   source "client.rb.erb"
 
  91 file "/etc/chef/client.pem" do
 
  97 template "/etc/chef/report.rb" do
 
  98   source "report.rb.erb"
 
 106 template "/etc/logrotate.d/chef" do
 
 107   source "logrotate.erb"
 
 113 directory node[:ohai][:plugin_dir] do
 
 119 directory "/var/log/chef" do
 
 125 systemd_service "chef-client" do
 
 126   description "Chef client"
 
 127   exec_start "/usr/bin/chef-client"
 
 131 systemd_timer "chef-client" do
 
 132   description "Chef client"
 
 133   after "network.target"
 
 135   on_unit_inactive_sec 25 * 60
 
 136   randomized_delay_sec 10 * 60
 
 139 service "chef-client.timer" do
 
 140   action [:enable, :start]