]> git.openstreetmap.org Git - chef.git/blob - cookbooks/chef/recipes/default.rb
Merge remote-tracking branch 'github/pull/670'
[chef.git] / cookbooks / chef / recipes / default.rb
1 #
2 # Cookbook:: chef
3 # Recipe:: default
4 #
5 # Copyright:: 2010, OpenStreetMap Foundation
6 #
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
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 cache_dir = Chef::Config[:file_cache_path]
21
22 chef_version = node[:chef][:client][:version]
23
24 chef_platform = if platform?("debian")
25                   "debian"
26                 else
27                   "ubuntu"
28                 end
29
30 chef_arch = if arm?
31               "arm64"
32             else
33               "amd64"
34             end
35
36 os_release = if platform?("debian") && node[:lsb][:release].to_f > 11
37                11
38              else
39                node[:lsb][:release]
40              end
41
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"
45   os_release = "22.04"
46 end
47
48 chef_package = "chef_#{chef_version}-1_#{chef_arch}.deb"
49
50 directory "/var/cache/chef" do
51   action :delete
52   recursive true
53 end
54
55 Dir.glob("#{cache_dir}/chef_*.deb").each do |deb|
56   next if deb == "#{cache_dir}/#{chef_package}"
57
58   file deb do
59     action :delete
60     backup false
61   end
62 end
63
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}"
66   owner "root"
67   group "root"
68   mode "644"
69   backup false
70   ignore_failure true
71 end
72
73 dpkg_package "chef" do
74   source "#{cache_dir}/#{chef_package}"
75   version "#{chef_version}-1"
76 end
77
78 directory "/etc/chef" do
79   owner "root"
80   group "root"
81   mode "755"
82 end
83
84 template "/etc/chef/client.rb" do
85   source "client.rb.erb"
86   owner "root"
87   group "root"
88   mode "640"
89 end
90
91 file "/etc/chef/client.pem" do
92   owner "root"
93   group "root"
94   mode "400"
95 end
96
97 template "/etc/chef/report.rb" do
98   source "report.rb.erb"
99   owner "root"
100   group "root"
101   mode "644"
102 end
103
104 template "/etc/logrotate.d/chef" do
105   source "logrotate.erb"
106   owner "root"
107   group "root"
108   mode "644"
109 end
110
111 directory node[:ohai][:plugin_dir] do
112   owner "root"
113   group "root"
114   mode "755"
115 end
116
117 directory "/var/log/chef" do
118   owner "root"
119   group "root"
120   mode "755"
121 end
122
123 systemd_service "chef-client" do
124   description "Chef client"
125   exec_start "/usr/bin/chef-client"
126   nice 10
127 end
128
129 systemd_timer "chef-client" do
130   description "Chef client"
131   after "network.target"
132   on_active_sec 60
133   on_unit_inactive_sec 25 * 60
134   randomized_delay_sec 10 * 60
135 end
136
137 service "chef-client.timer" do
138   action [:enable, :start]
139 end