Forum: CFEngine Help
Subject: Clarification on parameter passing with bundles / classes
Author: frans
Link to topic: https://cfengine.com/forum/read.php?3,24247,24247#msg-24247
Hi -
I'm seeing some unexpected behavior when invoking a method bundle with a class
as an argument. I am sure I am misunderstanding some aspect of cfengine
behavior so I'm hoping for clarification.
I have four zip files defined in a slist that I copy in from a remote host and
activate classes of the same name if a new file was ready for copy. A method
is then invoked with the zip file name as the lone argument if and only if a
class of the same name was defined. The method bundle then defines a local
class of the argument and manipulates the zip file differently depending on
which file / class it is.
Here is the code:
Parent bundle:
classes:
"demo" expression => fileexists("/root/demo");
vars:
"zipfiles" slist => {
"blue",
"green",
"gold",
"black",
};
files:
"/somewhere/$(zipfiles).war"
create => "true",
copy_from =>
remote_dcp("$(def.source_dir)/zipfiles.war.$(sys.uqhost)","$(sys.policy_hub)"),
classes => if_repaired("$(zipfiles)"),
action => "background";
methods:
centos_6_0.demo::
"any" usebundle => warunzip("$(zipfiles)"),
ifvarclass => "$(zipfiles)";
The "warunzip" bundle is as follows:
bundle agent warunzip(name)
{
classes:
# Declare this class again as classes don't traverse bundles
"demo" expression => fileexists("/root/.tmdemo");
"$(name)" or => { "$(name)" };
files:
demo::
# Need to clean up prior directory
"/somewhere/$(name)/."
delete => tidy,
depth_search => recurse("inf"),
ifvarclass => canonify("$(name)");
commands:
demo.blue::
"/usr/bin/unzip -uo /somewhere/$(name).war -d /this/path/",
ifvarclass => "black",
contain => in_shell;
demo.green::
"/usr/bin/unzip -uo /somewhere/$(name).war -d
/this/OTHER/PATH/ ",
ifvarclass => "green",
contain => in_shell;
}
The first problem is that I only see the warunzip method getting invoked twice
even though output confirms that all members of the slist needed copying and
were activated as classes.
cf3> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
cf3> BUNDLE warunzip( {'blue'} )
cf3> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
cf3> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
cf3> BUNDLE warunzip( {'green'} )
cf3> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The second problem is that the commands: classes are being ignored. The
green.war file is not destined for this extraction path but that's how it gets
unzip'd:
cf3> -> Executing '/usr/bin/unzip -uo /somewhere/green.war -d /this/path/'
...(timeout=-678,owner=-1,group=-1)
Where am I going wrong?
Thanks,
F
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine