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