]> git.openstreetmap.org Git - chef.git/blob - cookbooks/dns/recipes/default.rb
dns: Update dnscontrol v3.0.0 -> v3.2.0
[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 "git"
21 include_recipe "apache"
22
23 geoservers = search(:node, "roles:geodns").collect(&:name).sort
24
25 passwords = data_bag_item("dns", "passwords")
26
27 package %w[
28   make
29   parallel
30   rsync
31   perl
32   libdigest-sha-perl
33   libjson-xs-perl
34   libwww-perl
35   libxml-treebuilder-perl
36   libxml-writer-perl
37   libyaml-libyaml-perl
38   lockfile-progs
39 ]
40
41 remote_file "/usr/local/bin/dnscontrol" do
42   action :create
43   source "https://github.com/StackExchange/dnscontrol/releases/download/v3.2.0/dnscontrol-Linux"
44   owner "root"
45   group "root"
46   mode 0o755
47 end
48
49 directory "/srv/dns.openstreetmap.org" do
50   owner "root"
51   group "root"
52   mode 0o755
53 end
54
55 remote_directory "/srv/dns.openstreetmap.org/html" do
56   source "html"
57   owner "root"
58   group "root"
59   mode 0o755
60   files_owner "root"
61   files_group "root"
62   files_mode 0o644
63 end
64
65 zones = []
66
67 Dir.glob("/var/lib/dns/json/*.json").each do |kmlfile|
68   zone = File.basename(kmlfile, ".json")
69
70   template "/srv/dns.openstreetmap.org/html/#{zone}.html" do
71     source "zone.html.erb"
72     owner "root"
73     group "root"
74     mode 0o644
75     variables :zone => zone
76   end
77
78   zones.push(zone)
79 end
80
81 template "/srv/dns.openstreetmap.org/html/index.html" do
82   source "index.html.erb"
83   owner "root"
84   group "root"
85   mode 0o644
86   variables :zones => zones
87 end
88
89 ssl_certificate "dns.openstreetmap.org" do
90   domains ["dns.openstreetmap.org", "dns.osm.org"]
91   notifies :reload, "service[apache2]"
92 end
93
94 apache_site "dns.openstreetmap.org" do
95   template "apache.erb"
96   directory "/srv/dns.openstreetmap.org"
97   variables :aliases => ["dns.osm.org"]
98 end
99
100 template "/usr/local/bin/dns-update" do
101   source "dns-update.erb"
102   owner "root"
103   group "git"
104   mode 0o750
105   variables :passwords => passwords, :geoservers => geoservers
106 end
107
108 execute "dns-update" do
109   action :nothing
110   command "/usr/local/bin/dns-update"
111   user "git"
112   group "git"
113 end
114
115 directory "/var/lib/dns" do
116   owner "git"
117   group "git"
118   mode 0o2775
119   notifies :run, "execute[dns-update]"
120 end
121
122 template "/var/lib/dns/creds.json" do
123   source "creds.json.erb"
124   owner "git"
125   group "git"
126   mode 0o440
127   variables :passwords => passwords
128 end
129
130 cookbook_file "#{node[:dns][:repository]}/hooks/post-receive" do
131   source "post-receive"
132   owner "git"
133   group "git"
134   mode 0o750
135 end
136
137 template "/usr/local/bin/dns-check" do
138   source "dns-check.erb"
139   owner "root"
140   group "git"
141   mode 0o750
142   variables :passwords => passwords, :geoservers => geoservers
143 end
144
145 template "/etc/cron.d/dns" do
146   source "cron.erb"
147   owner "root"
148   group "root"
149   mode 0o644
150 end