75 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			75 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
#
 | 
						|
# Cookbook Name:: kosmos-base
 | 
						|
# Recipe:: letsencrypt
 | 
						|
#
 | 
						|
# The MIT License (MIT)
 | 
						|
#
 | 
						|
# Copyright:: 2019, Kosmos Developers
 | 
						|
#
 | 
						|
# Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
						|
# of this software and associated documentation files (the "Software"), to deal
 | 
						|
# in the Software without restriction, including without limitation the rights
 | 
						|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
						|
# copies of the Software, and to permit persons to whom the Software is
 | 
						|
# furnished to do so, subject to the following conditions:
 | 
						|
#
 | 
						|
# The above copyright notice and this permission notice shall be included in
 | 
						|
# all copies or substantial portions of the Software.
 | 
						|
#
 | 
						|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
						|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
						|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
						|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
						|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
						|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
						|
# THE SOFTWARE.
 | 
						|
 | 
						|
# Install certbot and set up hooks
 | 
						|
 | 
						|
# Remove the unless/else when we get rid of dev, running 15.04. No ppa for it
 | 
						|
unless node["lsb"]["codename"] == "vivid"
 | 
						|
  apt_repository "certbot" do
 | 
						|
    uri "ppa:certbot/certbot"
 | 
						|
  end
 | 
						|
 | 
						|
  package "certbot"
 | 
						|
else
 | 
						|
  remote_file "/usr/bin/certbot" do
 | 
						|
    source "https://dl.eff.org/certbot-auto"
 | 
						|
    mode 0755
 | 
						|
  end
 | 
						|
 | 
						|
  cron "renew Let's Encrypt certificates" do
 | 
						|
   hour "4"
 | 
						|
   mailto "logs@5apps.com"
 | 
						|
   command "/usr/bin/certbot -q renew"
 | 
						|
 end
 | 
						|
end
 | 
						|
 | 
						|
%w(deploy post pre).each do |subdir|
 | 
						|
  directory "/etc/letsencrypt/renewal-hooks/#{subdir}" do
 | 
						|
    recursive true
 | 
						|
    mode 0755
 | 
						|
    owner "root"
 | 
						|
    group "root"
 | 
						|
  end
 | 
						|
end
 | 
						|
 | 
						|
file "/etc/letsencrypt/renewal-hooks/deploy/nginx" do
 | 
						|
  content <<-EOF
 | 
						|
#!/usr/bin/env bash
 | 
						|
# Reloading nginx is enough to read the new certificates
 | 
						|
systemctl reload nginx
 | 
						|
  EOF
 | 
						|
  mode 0755
 | 
						|
  owner "root"
 | 
						|
  group "root"
 | 
						|
end
 | 
						|
 | 
						|
gandi_api_data_bag_item = data_bag_item('credentials', 'gandi_api_5apps')
 | 
						|
 | 
						|
template "/root/gandi_dns_certbot_hook.sh" do
 | 
						|
  variables gandi_api_key: gandi_api_data_bag_item["key"]
 | 
						|
  mode 0770
 | 
						|
end
 |