33 lines
		
	
	
		
			920 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			920 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
#
 | 
						|
# Cookbook:: kosmos_discourse
 | 
						|
# Recipe:: nginx
 | 
						|
#
 | 
						|
 | 
						|
domain = node['discourse']['domain']
 | 
						|
discourse_role = node['discourse']['role']
 | 
						|
 | 
						|
upstream_ip_addresses = []
 | 
						|
search(:node, "role:#{discourse_role}").each do |n|
 | 
						|
  upstream_ip_addresses << n["knife_zero"]["host"]
 | 
						|
end
 | 
						|
# No Discourse host, stop here
 | 
						|
if upstream_ip_addresses.empty?
 | 
						|
  Chef::Log.warn("No server with '#{discourse_role}' role. Stopping here.")
 | 
						|
  return
 | 
						|
end
 | 
						|
 | 
						|
tls_cert_for domain do
 | 
						|
  auth "gandi_dns"
 | 
						|
  action :create
 | 
						|
end
 | 
						|
 | 
						|
openresty_site domain do
 | 
						|
  template "nginx_conf.erb"
 | 
						|
  variables server_name:           domain,
 | 
						|
            ssl_cert:              "/etc/letsencrypt/live/#{domain}/fullchain.pem",
 | 
						|
            ssl_key:               "/etc/letsencrypt/live/#{domain}/privkey.pem",
 | 
						|
            upstream_port:         node['discourse']['port'],
 | 
						|
            upstream_name:         discourse_role,
 | 
						|
            upstream_ip_addresses: upstream_ip_addresses
 | 
						|
end
 |