2023-07-26 14:08:44 +02:00

32 lines
887 B
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
network = new_resource.network
domain = new_resource.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?
tls_cert_for domain do
auth "gandi_dns"
action :create
end
openresty_site domain do
template "nginx_conf_rskj.erb"
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"
end
end