Forum: CFEngine Help
Subject: Dealing with vars changing
Author: jonesy1234
Link to topic: https://cfengine.com/forum/read.php?3,24603,24603#msg-24603
I have a setup that requires a slightly different value for a var depending a
class. For example most of my systems run standard AIX syslog, two run
syslog-ng. The following code works ok but is there a better way of dealing
with situations like this?
bundle agent manage_core_services {
vars:
"service" slist => { "ntp", "ssh", "syslog", "inetd" };
methods:
"any" usebundle => fix_service("$(service)"),
comment => "Make sure the basic application services are
running";
}
#######################################################################
bundle agent fix_service(service) {
vars:
#NTP
"daemon" string => "xntpd";
"process" string => "/usr/sbin/xntpd";
"argument" string => " -x";
"cfg_file" string => "/etc/ntp.conf";
"cfg_source" string => "/etc/ntp.conf";
"mode" string => "0664";
"user" string => "root";
"group" string => "system";
#SSH
"daemon" string => "sshd";
"process" string => "/usr/sbin/sshd";
"argument" string => "";
"cfg_file" string => "/etc/ssh/sshd_config";
"cfg_source" string => "/etc/ssh/sshd_config";
"mode" string => "0644";
"user" string => "root";
"group" string => "system";
#INETD
#Everthing but the nim servers and vios use the standard inetd.conf file
"daemon" string => "inetd";
"process" string => "/usr/sbin/inetd";
"argument" string => "";
"cfg_file" string => "/etc/inetd.conf";
"mode" string => "0644";
"user" string => "root";
"group" string => "system";
#SYSLOG
#Everything but the nim servers run the standard syslog daemon
"mode" string => "0644";
"user" string => "root";
"group" string => "system";
"argument" string => "";
!nim_server::
#SYSLOG
"daemon" string => "syslogd";
"process" string => "/usr/sbin/syslogd";
"cfg_file" string => "/etc/syslog.conf";
"cfg_source" string => "/etc/syslog.conf";
#INETD
"cfg_source" string => "/etc/inetd.conf";
nim_server::
#SYSLOG Add exception for nim servers as they are running syslog-ng
"daemon" string => "syslogng";
"process" string => "/sbin/syslog-ng";
"cfg_file" string => "/etc/syslog-ng/syslog-ng.conf";
"cfg_source" string => "/etc/syslog-ng/syslog-ng.conf";
#INETD nim server uses different inetd conf file
"cfg_source" string => "/etc/inetd.conf.nim_server";
files:
"$(cfg_file[$(service)])"
comment => "Copy standard configuration file from master policy
server",
handle => "sync_standard_config_files",
copy_from =>
secure_cp("$(g.master_conf_root)$(cfg_source[$(service)])",
"$(g.policy_server)"),
perms =>
mog("$(mode[$(service)])","$(user[$(service)])","$(group[$(service)])"),
classes => if_repaired("$(service)_restart"),
action => log_to_syslog("repaired","file_$(cfg_file[$(service)])");
processes:
"$(process[$(service)])"
comment => "Check that the server process is running,
and start if necessary",
handle => "check_daemon_running",
restart_class => canonify("$(service)_restart");
commands:
"/usr/bin/stopsrc -s $(daemon[$(service)])",
handle => "stopsrc_daemon",
action => log_to_syslog("stop","daemon_$(daemon[$(service)])"),
ifvarclass => canonify("$(service)_restart");
"/usr/bin/startsrc -s $(daemon[$(service)]) -a \"$(argument[$(service)])\"",
handle => "startsrc_daemon",
action => log_to_syslog("start","daemon_$(daemon[$(service)])"),
ifvarclass => canonify("$(service)_restart");
}
So as you can see I have to set the vars twice, once for the nim_server class
and once for all others. The logic for this ordering can get very confusing
when there are multiple classes that need different values. The only other
option I can think of is putting a policy => "overridable"; on all the vars
that I want to have another value so they get redefined but that looks ugly in
the verbose output.
Anyone have any other suggestion?
Cheers
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine