wmdeit-cf-wmdelib/certbot.cf

119 lines
2.7 KiB
CFEngine3
Raw Normal View History

2023-09-24 16:16:22 +00:00
#
# Create SSL certificates using Letsencrypt
#
bundle agent certbot
{
vars:
"webroot" string => "$(wr)";
"renew" string => "$(rn)";
freebsd::
"certbot_dir" string => "/usr/local/etc/letsencrypt";
"exe" string => "/usr/local/bin/certbot";
2023-10-24 23:18:26 +00:00
"pkgs" slist => {"py39-certbot"};
2023-09-24 16:16:22 +00:00
debian::
"certbot_dir" string => "/etc/letsencrypt";
"exe" string => "/usr/bin/certbot";
2023-10-24 23:18:26 +00:00
"pkgs" slist => {"certbot"};
centos::
"certbot_dir" string => "/etc/letsencrypt";
"exe" string => "/usr/bin/certbot";
"pkgs" slist => {"epel-release","certbot"};
fedora::
"certbot_dir" string => "/etc/letsencrypt";
"exe" string => "/usr/bin/certbot";
"pkgs" slist => {"certbot"};
2023-09-24 16:16:22 +00:00
defaults:
"wr" string => "standalone";
"rn" string => "";
reports:
}
bundle agent install_certbot
{
2023-10-24 23:18:26 +00:00
methods:
"any" usebundle => wmde_install_packages( @(certbot.pkgs),"certbot"),
handle => "certbot_installed";
2023-09-27 21:05:52 +00:00
files:
freebsd::
"/etc/cron.d/certbot"
create => "true",
2023-10-02 06:09:38 +00:00
copy_from => local_cp("$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/certbot-cron.mustache");
2023-09-27 21:05:52 +00:00
# content => '#
# Managed by CFEngine
#
#SHELL=/bin/sh
#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#0 */12 * * * root certbot -q renew --no-random-sleep-on-renew
#';
2023-09-24 16:16:22 +00:00
}
bundle agent certbot_cert(site,webroot)
2023-09-24 16:16:22 +00:00
{
vars:
"domain" string => "$(site[domain])";
2023-10-29 00:07:43 +00:00
"keytype" string => "rsa";
2023-10-11 09:28:28 +00:00
"ds" slist => {"$(site[domain])"};
"domains" slist => sort(mergedata(@(ds),getvalues(@(site[aliases]))));
2023-09-24 16:16:22 +00:00
"site_json" string => storejson(@(site));
"args" string => string_mustache(
2023-10-29 00:07:43 +00:00
"--key-type $(keytype) --cert-name {{domain}} -d {{domain}} {{#aliases}} -d {{.}} {{/aliases}}",
2023-09-24 16:16:22 +00:00
@(site)
);
"webroot_arg" string => ifelse( strcmp("$(webroot)","standalone"),
"--standalone",
"--webroot -w $(webroot)");
files:
2023-10-04 06:52:01 +00:00
"$(sys.workdir)/data/agent/certbot/$(site[domain])-cert-created"
2023-09-24 16:16:22 +00:00
create => "true",
content => "$(args)",
classes => if_repaired(certbot_repaired);
classes:
"no_cert_file"
comment => "run certbot because no cert dir exists",
not => fileexists("$(certbot.certbot_dir)/live/$(site[domain])");
"run_certbot"
or => {no_cert_file, certbot_repaired};
defaults:
"webroot" string => "standalone";
"domain" string => "$(site[domain])";
2023-09-24 16:16:22 +00:00
methods:
"any" usebundle => install_certbot;
commands:
run_certbot::
"$(certbot.exe)"
depends_on => {"certbot_installed"},
handle => "certbot_dry_run_ok",
args => "certonly --dry-run --agree-tos -n $(webroot_arg) --expand --email $(site[email]) $(args)";
run_certbot::
"$(certbot.exe)"
depends_on => {"certbot_installed","certbot_dry_run_ok"},
args => "certonly --agree-tos -n $(webroot_arg) --expand --email $(site[email]) $(args)";
reports:
}