]> git.openstreetmap.org Git - chef.git/blob - cookbooks/dns/recipes/default.rb
dns: fix cookstyle error
[chef.git] / cookbooks / dns / recipes / default.rb
1 #
2 # Cookbook:: dns
3 # Recipe:: default
4 #
5 # Copyright:: 2011, 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 include_recipe "accounts"
21 include_recipe "apache"
22 include_recipe "git"
23
24 geoservers = search(:node, "roles:geodns").collect(&:name).sort
25
26 passwords = data_bag_item("dns", "passwords")
27
28 package %w[
29   make
30   parallel
31   rsync
32   perl
33   libdigest-sha-perl
34   libjson-xs-perl
35   libwww-perl
36   libxml-treebuilder-perl
37   libxml-writer-perl
38   libyaml-libyaml-perl
39   lockfile-progs
40 ]
41
42 cache_dir = Chef::Config[:file_cache_path]
43
44 dnscontrol_version = "3.20.0"
45
46 dnscontrol_arch = arm? ? "arm64" : "amd64"
47
48 remote_file "#{cache_dir}/dnscontrol-#{dnscontrol_version}.deb" do
49   source "https://github.com/StackExchange/dnscontrol/releases/download/v#{dnscontrol_version}/dnscontrol-#{dnscontrol_version}.#{dnscontrol_arch}.deb"
50   owner "root"
51   group "root"
52   mode "644"
53   backup false
54 end
55
56 dpkg_package "dnscontrol" do
57   action :nothing
58   source "#{cache_dir}/dnscontrol-#{dnscontrol_version}.deb"
59   subscribes :install, "remote_file[#{cache_dir}/dnscontrol-#{dnscontrol_version}.deb]"
60 end
61
62 directory "/srv/dns.openstreetmap.org" do
63   owner "root"
64   group "root"
65   mode "755"
66 end
67
68 remote_directory "/srv/dns.openstreetmap.org/html" do
69   source "html"
70   owner "root"
71   group "root"
72   mode "755"
73   files_owner "root"
74   files_group "root"
75   files_mode "644"
76 end
77
78 zones = []
79
80 Dir.glob("/var/lib/dns/json/*.json").each do |kmlfile|
81   zone = File.basename(kmlfile, ".json")
82
83   template "/srv/dns.openstreetmap.org/html/#{zone}.html" do
84     source "zone.html.erb"
85     owner "root"
86     group "root"
87     mode "644"
88     variables :zone => zone
89   end
90
91   zones.push(zone)
92 end
93
94 template "/srv/dns.openstreetmap.org/html/index.html" do
95   source "index.html.erb"
96   owner "root"
97   group "root"
98   mode "644"
99   variables :zones => zones
100 end
101
102 ssl_certificate "dns.openstreetmap.org" do
103   domains ["dns.openstreetmap.org", "dns.osm.org"]
104   notifies :reload, "service[apache2]"
105 end
106
107 apache_site "dns.openstreetmap.org" do
108   template "apache.erb"
109   directory "/srv/dns.openstreetmap.org"
110   variables :aliases => ["dns.osm.org"]
111 end
112
113 template "/usr/local/bin/dns-update" do
114   source "dns-update.erb"
115   owner "root"
116   group "git"
117   mode "750"
118   variables :passwords => passwords, :geoservers => geoservers
119 end
120
121 execute "dns-update" do
122   action :nothing
123   command "/usr/local/bin/dns-update"
124   user "git"
125   group "git"
126 end
127
128 directory "/var/lib/dns" do
129   owner "git"
130   group "git"
131   mode "2775"
132   notifies :run, "execute[dns-update]"
133 end
134
135 template "/var/lib/dns/creds.json" do
136   source "creds.json.erb"
137   owner "git"
138   group "git"
139   mode "440"
140   variables :passwords => passwords
141 end
142
143 template "/var/lib/dns/include/geo.js" do
144   source "geo.js.erb"
145   owner "git"
146   group "git"
147   mode "440"
148   variables :geoservers => geoservers
149   only_if { ::Dir.exist?("/var/lib/dns/include") }
150 end
151
152 cookbook_file "#{node[:dns][:repository]}/hooks/post-receive" do
153   source "post-receive"
154   owner "git"
155   group "git"
156   mode "750"
157   only_if { ::Dir.exist?("#{node[:dns][:repository]}/hooks") }
158 end
159
160 template "/usr/local/bin/dns-check" do
161   source "dns-check.erb"
162   owner "root"
163   group "git"
164   mode "750"
165   variables :passwords => passwords, :geoservers => geoservers
166 end
167
168 cron_d "dns" do
169   minute "*/3"
170   user "git"
171   command "/usr/local/bin/dns-check"
172   mailto "admins@openstreetmap.org"
173 end