2023-06-18 16:55:38 +02:00

38 lines
1.0 KiB
Ruby

resource_name :rskj_nginx_site
provides :rskj_nginx_site
property :network, String, required: true, name_property: true
property :domain, String, required: true
action :create do
include_recipe "kosmos-nginx"
network = new_resource.network
domain = new_resource.domain
nginx_certbot_site domain
upstream_hosts = []
search(:node, "role:rskj_#{network}").each do |node|
upstream_hosts << node["knife_zero"]["host"]
end
upstream_hosts.push("localhost") if upstream_hosts.empty?
template "#{node['nginx']['dir']}/sites-available/#{domain}" do
source "nginx_conf_rskj.erb"
owner 'www-data'
mode 0640
variables domain: domain,
upstream_name: "rskj_#{network}",
upstream_hosts: upstream_hosts,
upstream_port: "4444",
ssl_cert: "/etc/letsencrypt/live/#{domain}/fullchain.pem",
ssl_key: "/etc/letsencrypt/live/#{domain}/privkey.pem"
notifies :reload, 'service[nginx]', :delayed
end
nginx_site domain do
action :enable
end
end