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