wmdeit-cf-wmdelib/certbot.cf

114 lines
2.4 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";
"pkg" string => "py39-certbot";
debian::
"certbot_dir" string => "/etc/letsencrypt";
"exe" string => "/usr/bin/certbot";
"pkg" string => "certbot";
defaults:
"wr" string => "standalone";
"rn" string => "";
reports:
}
bundle agent install_certbot
{
packages:
freebsd::
"$(certbot.pkg)"
policy => "present",
package_module => pkg,
handle => "certbot_installed";
debian::
"$(certbot.pkg)"
policy => "present",
package_module => apt_get,
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-09-24 16:16:22 +00:00
"site_json" string => storejson(@(site));
"args" string => string_mustache(
"-d {{domain}} {{#aliases}} -d {{.}} {{/aliases}}",
@(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:
}