Forum: Cfengine Help
Subject: Re: templating and need for action
Author: bglomm
Link to topic: https://cfengine.com/forum/read.php?3,19663,19665#msg-19665
thnx Neil,
here the three files I'm working with... all works fine except that on each run
the snmpd.conf gets repaired... even if is not necessary ....
the "top layer":
bundle agent sdk_snmpd_config {
vars:
any::
"snmp2cstring" string => "public";
"nmsaddr" string => "192.168.10.10/32";
inhouse::
"syslocstring" string => "home";
outhosuse::
"syslocstring" string => "outhouse location";
packages:
"snmpd"
comment => "make sure snmpd is installed",
package_policy => "add",
package_method => apt;
methods:
"any"
comment => "get the snmpd.conf template",
usebundle =>
get_template("/etc/snmp/snmpd.conf","400","root","root"),
classes => if_repaired("restart_snmpd");
commands:
restart_snmpd::
"/etc/init.d/snmpd restart",
comment => "restart snmpd after having reconfigured
snmpd.conf";
}
the get_template bundle:
bundle agent get_template(final_destination,mode,owner,group) {
vars:
"confmasterfiles" string => "$(update.masterfiles)/conf_files";
"this_template" string => lastnode("$(final_destination)","/");
files:
"$(final_destination).staging"
comment => "Get template and expand variables for this host",
perms => mog("400","root","root"),
copy_from =>
secure_cp("$(confmasterfiles)/$(this_template)","$(update.cfmaster)"),
action => if_elapsed("60");
"$(final_destination)"
comment => "Expand the template",
create => "true",
edit_line => expand_template("$(final_destination).staging"),
edit_defaults => empty,
perms => mog("$(mode)","$(owner)","$(group)"),
action => if_elapsed("60");
}
finally the template I'm working with
agentAddress udp:$(sys.ipv4):161
view systemonly included .1.3.6.1.2.1
rocommunity $(sdk_snmpd_config.snmp2cstring)
$(sdk_snmpd_config.nmsaddr) -V systemonly
sysLocation $(sdk_snmpd_config.syslocstring)
sysContact bglomm
sysServices 72
includeAllDisks 10%
load 12 10 5
master agentx
and here the output of cf-agent -vIK:
cf3 Done checking packages and patches
cf3 ???????????????????????????????????????????????????????????????
cf3 -> Package version was not specified
cf3 -> Looking for (snmpd,*,*)
cf3 -> Matched name snmpd
cf3 -> Matched version *
cf3 -> Looking for (snmpd,*,*)
cf3 -> Matched name snmpd
cf3 -> Matched version *
cf3 -> 1 package(s) matching the name "snmpd" already installed
cf3 -> 1 package(s) match the promise body's criteria fully
cf3 -> Package promises to refer to itself as "snmpd" to the manager
cf3 -> Package version seems to match criteria
cf3 -> Package already installed, so we never add it again
cf3
cf3 =========================================================
cf3 commands in bundle sdk_snmpd_config (1)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cf3 Skipping whole next promise (/etc/init.d/snmpd restart), as context
restart_snmpd is not relevant
cf3 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cf3
cf3 =========================================================
cf3 methods in bundle sdk_snmpd_config (1)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 .........................................................
cf3 Promise handle:
cf3 Promise made by: any
cf3
cf3 Comment: snmpd.conf is a sensitive file so we keep full control about
it
cf3 .........................................................
cf3
cf3
cf3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
cf3 BUNDLE get_template( {'/etc/snmp/snmpd.conf','400','root','root'} )
cf3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
cf3
cf3 ? Augment scope get_template with final_destination
cf3 ? Augment scope get_template with mode
cf3 ? Augment scope get_template with owner
cf3 ? Augment scope get_template with group
cf3
cf3 =========================================================
cf3 vars in bundle get_template (1)
cf3 =========================================================
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 + Private classes augmented:
cf3
cf3 - Private classes diminished:
cf3
cf3
cf3
cf3 =========================================================
cf3 files in bundle get_template (1)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 .........................................................
cf3 Promise handle:
cf3 Promise made by: /etc/snmp/snmpd.conf.staging
cf3
cf3 Comment: Get template and expand variables for this host
cf3 .........................................................
cf3
cf3 -> Handling file existence constraints on /etc/snmp/snmpd.conf.staging
cf3 -> File permissions on /etc/snmp/snmpd.conf.staging as promised
cf3 -> Handling file existence constraints on /etc/snmp/snmpd.conf.staging
cf3 -> File permissions on /etc/snmp/snmpd.conf.staging as promised
cf3 -> Copy file /etc/snmp/snmpd.conf.staging from
/srv/cfengine3/masterfiles/conf_files/snmpd.conf check
cf3 No existing connection to 10.0.0.99 is established...
cf3 Set cfengine port number to 5308 = 5308
cf3 -> Connect to 10.0.0.99 = 10.0.0.99 on port 5308
cf3 LastSaw host 10.0.0.99 now
cf3 Loaded /var/lib/cfengine3/ppkeys/root-10.0.0.99.pub
cf3 .....................[.h.a.i.l.].................................
cf3 Strong authentication of server=10.0.0.99 connection confirmed
cf3 -> Destination file "/etc/snmp/snmpd.conf.staging" already exists
cf3 -> Not attempting to preserve file permissions from the source
cf3 -> File permissions on /etc/snmp/snmpd.conf.staging as promised
cf3 -> File /etc/snmp/snmpd.conf.staging is an up to date copy of source
cf3 Performance(Copy(10.0.0.99:/srv/cfengine3/masterfiles/conf_files/snmpd.conf
> /etc/snmp/snmpd.conf.staging)): time=0.0007 secs, av=0.0007 +/- 0.0026
cf3 Existing connection just became free...
cf3
cf3 .........................................................
cf3 Promise handle:
cf3 Promise made by: /etc/snmp/snmpd.conf
cf3
cf3 Comment: Expand the template
cf3 .........................................................
cf3
cf3 -> Using literal pathtype for /etc/snmp/snmpd.conf
cf3 -> File "/etc/snmp/snmpd.conf" exists as promised
cf3 -> Handling file existence constraints on /etc/snmp/snmpd.conf
cf3 -> File permissions on /etc/snmp/snmpd.conf as promised
cf3 -> Handling file existence constraints on /etc/snmp/snmpd.conf
cf3 -> File permissions on /etc/snmp/snmpd.conf as promised
cf3 -> Handling file edits in edit_line bundle expand_template
cf3
cf3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
cf3 BUNDLE expand_template( {'/etc/snmp/snmpd.conf.staging'} )
cf3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
cf3 ? Augment scope expand_template with templatefile
cf3 ?? Private class context
cf3
cf3
cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = =
cf3 insert_lines in bundle expand_template
cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = =
cf3
cf3
cf3 .........................................................
cf3 Promise handle:
cf3 Promise made by: /etc/snmp/snmpd.conf.staging
cf3
cf3 Comment: Expand variables in the template file
cf3 .........................................................
cf3
cf3 -> Promised file line "### snmpd.conf managed by cfengine." exists within
file /etc/snmp/snmpd.conf (promise kept)
cf3 -> Promised file line "### DO NOT EDIT THIS FILE" exists within file
/etc/snmp/snmpd.conf (promise kept)
cf3 -> Promised file line "### [email protected]" exists within
file /etc/snmp/snmpd.conf (promise kept)
cf3 -> Promised file line "" exists within file /etc/snmp/snmpd.conf (promise
kept)
cf3 -> Promised file line "agentAddress udp:10.0.6.134:161" exists
within file /etc/snmp/snmpd.conf (promise kept)
cf3 -> Promised file line "" exists within file /etc/snmp/snmpd.conf (promise
kept)
cf3 -> Promised file line "view systemonly included
.1.3.6.1.2.1" exists within file /etc/snmp/snmpd.conf (promise kept)
cf3 -> Promised file line "" exists within file /etc/snmp/snmpd.conf (promise
kept)
cf3 -> Promised file line "rocommunity Aiaf1yaife7eirooKimuPifsd
10.0.0.97/32 -V systemonly" exists within file /etc/snmp/snmpd.conf
(promise kept)
cf3 -> Promised file line "" exists within file /etc/snmp/snmpd.conf (promise
kept)
cf3 -> Promised file line "sysLocation Potsdamer Platz" exists within
file /etc/snmp/snmpd.conf (promise kept)
cf3 -> Promised file line "sysContact bglomm " exists within file
/etc/snmp/snmpd.conf (promise kept)
cf3 -> Promised file line "sysServices 72" exists within file
/etc/snmp/snmpd.conf (promise kept)
cf3 -> Promised file line "" exists within file /etc/snmp/snmpd.conf (promise
kept)
cf3 -> Promised file line "includeAllDisks 10%" exists within file
/etc/snmp/snmpd.conf (promise kept)
cf3 -> Promised file line "" exists within file /etc/snmp/snmpd.conf (promise
kept)
cf3 -> Promised file line "load 12 10 5" exists within
file /etc/snmp/snmpd.conf (promise kept)
cf3 -> Promised file line "" exists within file /etc/snmp/snmpd.conf (promise
kept)
cf3 -> Promised file line "master agentx" exists within file
/etc/snmp/snmpd.conf (promise kept)
cf3 ?? Private class context
cf3
cf3
cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = =
cf3 insert_lines in bundle expand_template
cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = =
cf3
cf3
cf3 .........................................................
cf3 Promise handle:
cf3 Promise made by: /etc/snmp/snmpd.conf.staging
cf3
cf3 Comment: Expand variables in the template file
cf3 .........................................................
cf3
cf3 -> This promise has already been verified
cf3 ?? Private class context
cf3
cf3
cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = =
cf3 insert_lines in bundle expand_template
cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = =
cf3
cf3
cf3 .........................................................
cf3 Promise handle:
cf3 Promise made by: /etc/snmp/snmpd.conf.staging
cf3
cf3 Comment: Expand variables in the template file
cf3 .........................................................
cf3
cf3 -> This promise has already been verified
cf3 -> No edit changes to file /etc/snmp/snmpd.conf need saving
cf3
cf3 =========================================================
cf3 vars in bundle get_template (2)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 + Private classes augmented:
cf3
cf3 - Private classes diminished:
cf3
cf3
cf3
cf3 =========================================================
cf3 files in bundle get_template (2)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 .........................................................
cf3 Promise handle:
cf3 Promise made by: /etc/snmp/snmpd.conf.staging
cf3
cf3 Comment: Get template and expand variables for this host
cf3 .........................................................
cf3
cf3 -> This promise has already been verified
cf3
cf3 .........................................................
cf3 Promise handle:
cf3 Promise made by: /etc/snmp/snmpd.conf
cf3
cf3 Comment: Expand the template
cf3 .........................................................
cf3
cf3 -> Using literal pathtype for /etc/snmp/snmpd.conf
cf3 -> This promise has already been verified
cf3
cf3 =========================================================
cf3 vars in bundle get_template (3)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 + Private classes augmented:
cf3
cf3 - Private classes diminished:
cf3
cf3
cf3
cf3 =========================================================
cf3 files in bundle get_template (3)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 .........................................................
cf3 Promise handle:
cf3 Promise made by: /etc/snmp/snmpd.conf.staging
cf3
cf3 Comment: Get template and expand variables for this host
cf3 .........................................................
cf3
cf3 -> This promise has already been verified
cf3
cf3 .........................................................
cf3 Promise handle:
cf3 Promise made by: /etc/snmp/snmpd.conf
cf3
cf3 Comment: Expand the template
cf3 .........................................................
cf3
cf3 -> Using literal pathtype for /etc/snmp/snmpd.conf
cf3 -> This promise has already been verified
cf3 -> Method invoked successfully
cf3 ?> defining promise result class restart_snmpd
cf3
cf3 =========================================================
cf3 vars in bundle sdk_snmpd_config (2)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cf3 Skipping whole next promise (syslocstring), as context outhosuse is not
relevant
cf3 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cf3
cf3 + Private classes augmented:
cf3
cf3 - Private classes diminished:
cf3
cf3
cf3
cf3 =========================================================
cf3 packages in bundle sdk_snmpd_config (2)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 =========================================================
cf3 commands in bundle sdk_snmpd_config (2)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3 -> Promiser string contains a valid executable (/etc/init.d/snmpd) - ok
cf3
cf3 .........................................................
cf3 Promise handle:
cf3 Promise made by: /etc/init.d/snmpd restart
cf3
cf3 Comment: restart snmpd after having reconfigured snmpd.conf
cf3 .........................................................
cf3
cf3 -> Executing '/etc/init.d/snmpd restart'
...(timeout=-678,owner=-1,group=-1)
cf3 -> (Setting umask to 77)
cf3 -> Finished script - succeeded /etc/init.d/snmpd restart
cf3 Q: "...it.d/snmpd rest": Restarting network management services: snmpd.
cf3 I: Last 1 QUOTed lines were generated by promiser "/etc/init.d/snmpd
restart"
cf3 -> Completed execution of /etc/init.d/snmpd restart
cf3
cf3 =========================================================
cf3 methods in bundle sdk_snmpd_config (2)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 =========================================================
cf3 vars in bundle sdk_snmpd_config (3)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cf3 Skipping whole next promise (syslocstring), as context outhosuse is not
relevant
cf3 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cf3
cf3 + Private classes augmented:
cf3
cf3 - Private classes diminished:
cf3
cf3
cf3
cf3 =========================================================
cf3 packages in bundle sdk_snmpd_config (3)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 =========================================================
cf3 commands in bundle sdk_snmpd_config (3)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3
cf3 =========================================================
cf3 methods in bundle sdk_snmpd_config (3)
cf3 =========================================================
cf3
cf3 Verifying SQL table promises is only available with Cfengine Nova or above
cf3 Outcome of version 0.01 (agent-0): Promises observed to be kept 99%,
Promises repaired 1%, Promises not repaired 0%
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine