wmdeit-cf-wmdelib/rspamd.cf

148 lines
3.8 KiB
CFEngine3

#
#
#
bundle agent rspamd(cfg)
{
classes:
"runpw" expression => isvariable("cfg[password]");
vars:
"tpl_deps" slist => { "rspamd_pkgs_installed","rspamd_cfg_dir_created" };
runpw::
"tpl_deps" slist => { "rspamd_pkgs_installed","rspamd_cfg_dir_created","rspamd_password_ready" };
any::
"cfgfiles" slist => {
"local.d/milter_headers.conf",
# "local.d/actions.conf",
"local.d/worker-normal.inc",
"local.d/worker-proxy.inc",
"local.d/worker-controller.inc",
"local.d/redis.conf",
# "local.d/classifier-bayes.conf",
# "local.d/worker-fuzzy.inc",
# "local.d/fuzzy_check.conf"
};
freebsd::
"pkgs" slist => {"rspamd"};
"cfg_dir" string => "/usr/local/etc/rspamd";
"service_name" string => "rspamd";
"root_user" string => "root";
"root_group" string => "wheel";
"rspamadm" string => "/usr/local/bin/rspamadm";
"rspamc" string => "/usr/local/bin/rspamc";
debian::
"pkgs" slist => {"rspamd"};
"cfg_dir" string => "/etc/rspamd";
"service_name" string => "rspamd";
"root_user" string => "root";
"root_group" string => "root";
"rspamadm" string => "/usr//bin/rspamadm";
"rspamc" string => "/usr/bin/rspamc";
centos::
"pkgs" slist => {"rspamd"};
"cfg_dir" string => "/etc/rspamd";
"service_name" string => "rspamd";
"root_user" string => "root";
"root_group" string => "root";
"rspamadm" string => "/usr//bin/rspamadm";
"rspamc" string => "/usr/bin/rspamc";
runpw::
"password" string => readfile("$(sys.workdir)/data/agent/rspamd/password-hash.txt"),
handle => "rspamd_password_ready",
depends_on => {"rspamd_password_hash_created"};
files:
runpw::
"$(sys.workdir)/data/agent/rspamd/password.txt"
create => "true",
content => "$(cfg[password])",
handle => "rspamd_password_created",
classes => if_repaired("rspamd_password_repaired");
methods:
runpw::
"any" usebundle => rspamd_create_password_hash,
depends_on => {"rspamd_password_created"},
handle => "rspamd_password_hash_created";
commands:
!runpw::
"/usr/bin/true"
depends_on => {"rspamd_password_created"},
handle => "rspamd_password_hash_created",
inform => "false";
methods:
"any" usebundle => install_rspamd_pkgs;
"any" usebundle => wmde_service("$(service_name)","rspamd_kept","rspamd_repaired"),
depends_on => {"rspamd_cfgs_done"};
files:
"$(cfg_dir)/."
perms => uperm("$(root_user)","$(root_group)","755"),
depends_on => { "rspamd_pkgs_installed" },
handle => "rspamd_cfg_dir_created";
"$(cfg_dir)/$(cfgfiles)"
create => "true",
edit_template => "$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/rspamd/$(cfgfiles).mustache",
template_method => "mustache",
perms => m("644"),
template_data => bundlestate("$(this.bundle)"),
depends_on => @(tpl_deps),
classes => if_repaired(rspamd_repaired),
handle => "rspamd_cfgs_done";
reports:
}
bundle agent rspamd_create_password_hash
{
classes:
"no_hash_file" expression => not(fileexists("$(sys.workdir)/data/agent/rspamd/password-hash.txt"));
files:
rspamd_password_repaired|no_hash_file::
"$(sys.workdir)/data/agent/rspamd/password-hash.txt"
content => execresult("$(rspamd.rspamadm) pw -p $(rspamd.cfg[password])","noshell"),
handle => "rspamd_password_hash_created";
}
bundle agent rspamd_install_yum_repo
{
classes:
centos::
"install_yum_repo" expression => not(fileexists("/etc/yum.repos.d/rspamd.repo"));
commands:
install_yum_repo::
"wget"
args => "-qO /etc/yum.repos.d/rspamd.repo https://rspamd.com/rpm-stable/centos-$(sys.os_version_major)/rspamd.repo && rpm --import https://rspamd.com/rpm-stable/gpg.key ",
contain => wmde_cmd_useshell;
}
bundle agent install_rspamd_pkgs
{
methods:
"any" usebundle => rspamd_install_yum_repo, handle => "rspamd_yum_repo_installed";
"any" usebundle => wmde_install_packages(@(rspamd.pkgs),"rspamd"),
depends_on => {"rspamd_yum_repo_installed"};
}