Running bundles in solo-mode from commandline with parameters

51 views
Skip to first unread message

Christian Linden

unread,
Sep 4, 2015, 6:58:41 AM9/4/15
to help-cfengine
Hi,

is it possible to run a bundle solo like: cf-agent -KIf /path/to/my/promise.cf -b mybundle myparameter?

This way it doesn't work.. any trick how to mark the paramenter?
Or is it not thought to be uses this way?
cf-agent --h doesn't help either..

Thanks,
Chris

Marco Marongiu

unread,
Sep 4, 2015, 8:38:07 AM9/4/15
to help-c...@googlegroups.com
On 04/09/15 12:58, Christian Linden wrote:
> is it possible to run a bundle solo like: cf-agent -KIf
> /path/to/my/promise.cf -b mybundle myparameter?

I don't think you can run a bundle from the command line *and* pass a
parameter. What I usually do for testing purposes is to create a bundle
test_mybundle, and that bundle will call mybundle with some test
parameters via a methods promise. That's the closest I could get.

-- bronto


Nick Anderson

unread,
Sep 4, 2015, 9:03:16 AM9/4/15
to Marco Marongiu, help-c...@googlegroups.com
On 09/04/2015 07:38 AM, Marco Marongiu wrote:
> I don't think you can run a bundle from the command line *and* pass a
> parameter. What I usually do for testing purposes is to create a bundle
> test_mybundle, and that bundle will call mybundle with some test
> parameters via a methods promise. That's the closest I could get.

That's correct. cfengine expects that you **plan_ahead**. You can
override the bundlesequence on the command line

cf-agent --bundlesequence bundle1,bundle2,bundle3

cf-agent -b bundle3,bundle2,bundle1

You can also define classes

cf-agent --define class1,class2

cf-agent -D class1,class2

There is no way to activate a bundle with parameters directly. So you
must activate a bundle that in turn activates the bundle with
parameters. 3.7 makes running standalone policy slightly easier because
the default bundle sequence is "main". This allows you to do something
like this:

bundle agent main
{
vars:
any::
"retention" string => "10";

low_disk_space::
"retention" string => "1";

methods:
"Log rotation"
usebundle => log_rotation("/var/log", $(retention) );
}

bundle agent log_rotation(dir, days)
{
... stuff
}


Then you can set retention to 1 by defining the low_disk_space class.

cf-agent -Kf ./policy_file.cf --define low_disk_space

Christian Linden

unread,
Sep 4, 2015, 9:58:08 AM9/4/15
to help-cfengine, bront...@gmail.com
Nick & Bronto,

thanks for clear answers and cool example, Nick.
Got it with the methods-way, do-able.

Have great weekends,
Chris

Gregory Matthews

unread,
Sep 7, 2015, 6:35:40 AM9/7/15
to help-c...@googlegroups.com
dont know if it helps but I define a function in my bash environment
that looks like this:

cf-just ()
{
/usr/bin/sudo /var/cfengine/bin/cf-agent -Ib
dls_mode,modules,global_classes,g,$@
}

The bundles listed above are the minimum necessary for setting certain
global classes and variables and it allows me to run a single bundle
like this:

cf-just dls_nx

and I can also set/unset classes on the command line using -D/-N.

G

>
> Thanks,
> Chris
>
> --
> You received this message because you are subscribed to the Google
> Groups "help-cfengine" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to help-cfengin...@googlegroups.com
> <mailto:help-cfengin...@googlegroups.com>.
> To post to this group, send email to help-c...@googlegroups.com
> <mailto:help-c...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/help-cfengine.
> For more options, visit https://groups.google.com/d/optout.


--
Greg Matthews 01235 778658
Scientific Computing Group Leader
Diamond Light Source Ltd. OXON UK

--
This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd.
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom

Christian Linden

unread,
Sep 7, 2015, 8:02:03 AM9/7/15
to help-cfengine, greg.m...@diamond.ac.uk
Cool idea, Greg, but not what I wanted to archieve against the cfengine-thinking-way =)
This is not a parameter for a bundle but an optional bundle.

Thanks for looking into it!
Best,
Chris

Ted Zlatanov

unread,
Sep 8, 2015, 12:58:57 PM9/8/15
to help-c...@googlegroups.com
Take a look at feature.cf:
https://github.com/cfengine/masterfiles/blob/master/lib/3.8/feature.cf

It looks for specifically named classes and parses them out to extract
parameters. For instance, from its docs: set class `xyz` for 10 minutes, class `qpr`
for 100 minutes, and `ijk` for 90m minutes. Unset class `abc`.

cf-agent -I -f ./feature.cf -b feature -Dfeature_set_10_xyz,feature_set_100_qpr,feature_set_90m_ijk,feature_unset_abc

You can adapt this approach easily to your own needs.

Ted

Christian Linden

unread,
Sep 10, 2015, 6:29:34 AM9/10/15
to help-cfengine
Wow, Ted, that's tricky.. interesting! ..but too hard for my non-coding mind to understand in detail.. maybe later =) 

Thanks,
Chris
Reply all
Reply to author
Forward
0 new messages