2 # Cookbook Name:: letsencrypt
5 # Copyright 2017, OpenStreetMap Foundation
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
11 # https://www.apache.org/licenses/LICENSE-2.0
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.
20 include_recipe "apache"
22 keys = data_bag_item("chef", "keys")
29 directory "/etc/letsencrypt" do
35 directory "/var/lib/letsencrypt" do
41 directory "/var/log/letsencrypt" do
47 directory "/srv/acme.openstreetmap.org" do
53 directory "/srv/acme.openstreetmap.org/html" do
59 ssl_certificate "acme.openstreetmap.org" do
60 domains ["acme.openstreetmap.org", "acme.osm.org"]
61 notifies :reload, "service[apache2]"
64 apache_site "acme.openstreetmap.org" do
66 directory "/srv/acme.openstreetmap.org"
69 directory "/srv/acme.openstreetmap.org/config" do
75 directory "/srv/acme.openstreetmap.org/work" do
81 directory "/srv/acme.openstreetmap.org/logs" do
87 directory "/srv/acme.openstreetmap.org/.chef" do
93 file "/srv/acme.openstreetmap.org/.chef/client.pem" do
94 content keys["letsencrypt"].join("\n")
100 cookbook_file "/srv/acme.openstreetmap.org/.chef/knife.rb" do
107 remote_directory "/srv/acme.openstreetmap.org/bin" do
117 directory "/srv/acme.openstreetmap.org/requests" do
123 certificates = search(:node, "letsencrypt:certificates").each_with_object({}) do |n, c|
124 n[:letsencrypt][:certificates].each do |name, details|
125 c[name] ||= details.merge(:nodes => [])
127 c[name][:nodes] << { :name => n[:fqdn], :address => n[:ipaddress] }
131 certificates.each do |name, details|
132 template "/srv/acme.openstreetmap.org/requests/#{name}" do
140 execute "/srv/acme.openstreetmap.org/requests/#{name}" do
142 command "/srv/acme.openstreetmap.org/requests/#{name}"
143 cwd "/srv/acme.openstreetmap.org"
146 subscribes :run, "template[/srv/acme.openstreetmap.org/requests/#{name}]"
150 template "/srv/acme.openstreetmap.org/bin/check-certificates" do
151 source "check-certificates.erb"
155 variables :certificates => certificates
158 template "/etc/cron.d/letsencrypt" do