Hi
I am looking for the best way of automating enabling apache modules and configs. In Debian this is done with a2enmod and a2enconf commands which create a symlink in conf-enabled and mods-enabled folders.
EnableModules.cf
Code:
bundle agent enable_modules
{
classes:
"hasApache24" expression => fileexists("/usr/sbin/apache2ctl");
"mod_headers_enabled" expression => islink("/etc/apache2/mods-enabled/headers.load");
commands:
hasApache24.!mod_headers_enabled::
"/usr/sbin/a2enmod headers"
comment => "enabling apache module headers";
}
and when I run it
Code:
~# cf-agent -b enable_modules -f ./EnableModules.cf
notice: Q: "...in/a2enmod head": Enabling module headers.
Q: "...in/a2enmod head": To activate the new configuration, you need to run:
Q: "...in/a2enmod head": systemctl restart apache2
~# l /etc/apache2/mods-enabled/headers.load
lrwxrwxrwx 1 root root 30 Jun 5 15:46 /etc/apache2/mods-enabled/headers.load -> ../mods-available/headers.load
But that requires defining a class for each module to be enabled
I'd like to have a list
EnableModules2.cf
Code:
bundle agent enable_modules2
{
classes:
"hasApache24" expression => fileexists("/usr/sbin/apache2ctl");
vars:
"apache_modules"
handle => "Apache_Modules",
comment => "List of addiional Apache modules",
slist => { "headers", "rewrite", "expires", "mime", "deflate", "unique_id", "ssl", "allowmethods" };
commands:
# adding Apache modules
hasApache24::
"/usr/sbin/a2enmod $(apache_modules)"
comment => "enabling apache modules $(apache_modules)";
}
but that repairs promises on every run
Code:
~# cf-agent -K -b enable_modules2 -f ./EnableModules2.cf
notice: Q: "...in/a2enmod head": Module headers already enabled
notice: Q: "...in/a2enmod rewr": Module rewrite already enabled
notice: Q: "...in/a2enmod expi": Module expires already enabled
notice: Q: "...in/a2enmod mime": Module mime already enabled
notice: Q: "...in/a2enmod defl": Considering dependency filter for deflate:
Q: "...in/a2enmod defl": Module filter already enabled
Q: "...in/a2enmod defl": Module deflate already enabled
notice: Q: "...in/a2enmod uniq": Module unique_id already enabled
notice: Q: "...in/a2enmod ssl": Considering dependency setenvif for ssl:
Q: "...in/a2enmod ssl": Module setenvif already enabled
Q: "...in/a2enmod ssl": Considering dependency mime for ssl:
Q: "...in/a2enmod ssl": Module mime already enabled
Q: "...in/a2enmod ssl": Considering dependency socache_shmcb for ssl:
Q: "...in/a2enmod ssl": Module socache_shmcb already enabled
Q: "...in/a2enmod ssl": Module ssl already enabled
notice: Q: "...in/a2enmod allo": Module allowmethods already enabled
Is there any better way to enable apache2 modules and configs in CFEngine3? I was hoping to have something similar to installing packages, but could not find any example.
Thanks
Greg