CFEngine Help: Re: False report of "no constrants" in constrained classes promises.

2012-09-23 Thread no-reply
Forum: CFEngine Help
Subject: Re: False report of "no constrants" in constrained classes promises.
Author: mark
Link to topic: https://cfengine.com/forum/read.php?3,27501,27506#msg-27506

On 09/23/2012 02:42 AM, Aleksey Tsalolikhin wrote:
> Situation:  I want to target a promise to a certain group of servers.
> However I want to
> abstract the elements of that group from the promises that target that
> group, so that
> when I add an element to that group, I only need to update *one*
> promise, the one
> enumerating that group.
>
>
> (Let's assume my hosname is "web01".  The list is { "web01", "web02", "web03" 
> }:
>
>
> {{{
>
>
> bundle common global_vars {
>
>   vars:
>  "webservers"
> slist => { "web01", "web02", "web03" };
>
> }
>
>
> }}}
>
>


Hi Aleksey, here are my suggestions.

>
> Attempt 1:  Loop over the list of server names, checking if any match
> the current context.
> FAIL.  3.3.5 complains "No constraints for class promise webfarm":
>
> {{{
> bundle common global_classes {
>
> classes:
>
> "webfarm"
>
> ifvarclass => canonify("$(global_vars.webservers)");
>
> }
>
> }}}
>
> The body of a promise details and constrains its nature.  This promise
> is constrained by the ifvarclass attribute.

That's true but there are no constraints that determine the class. It's like 
writing

 classes:

solaris::

   "webfarm";  # missing right hand side definition


I think what you are trying to write is this:


vars:
"webservers" slist => { "web01", "web02", "web03" };

classes:

   "webclass" or => { "@(webservers)" };


Then, e.g.

reports:

  webclass:: "something or other";

or

  "something or other"ifvarclass => "webclass";

This satisfies all of the points above. You slipped into thinking imperatively, 
I think, but there is no need to struggle with this.

M

-- 

CTO and Founder
CFEngine

http://www.cfengine.com
http://www.markburgess.org
Twitter: @markburgess_osl, @CFEngine_news

___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


Re: Shellcommands get SIGTERM'ed. ExpireAfter not working.

2012-09-23 Thread Aleksey Tsalolikhin
Is upgrading to CFEngine 3 an option? 3 is much improved compared to 2.

Why is apt-get taking longer than it used to?

Aleksey

On Sep 16, 2012 11:46 PM, "Sander Smeenk"  wrote:
>
> Quoting Sander Smeenk (ssme...@freshdot.net):
>
> > Any light on why i cant seem to put an end to the brutal killings? :/
>
> Anyone?
>
> --
> | Before borrowing money from a friend, decide which you need more.
> | 4096R/20CC6CD2 - 6D40 1A20 B9AA 87D4 84C7  FBD6 F3A9 9442 20CC 6CD2
> ___
> Help-cfengine mailing list
> Help-cfengine@cfengine.org
> https://cfengine.org/mailman/listinfo/help-cfengine
___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


CFEngine Help: Starting cf-execd from inittab

2012-09-23 Thread no-reply
Forum: CFEngine Help
Subject: Starting cf-execd from inittab
Author: aleksey_c
Link to topic: https://cfengine.com/forum/read.php?3,27509,27509#msg-27509

Does anyone have experience of starting cf-execd from inittab with respawn 
option?

For example

ce:2345:respawn:/var/cfengine/bin/cf-execd --no-fork


Seems like at least during binary updates respawn option should be disabled. 
Are there any other potential problems?

___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


CFEngine Help: Re: Starting cf-execd from inittab

2012-09-23 Thread no-reply
Forum: CFEngine Help
Subject: Re: Starting cf-execd from inittab
Author: neilhwatson
Link to topic: https://cfengine.com/forum/read.php?3,27509,27510#msg-27510

Why the --no-fork?

___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


CFEngine Help: Re: Starting cf-execd from inittab

2012-09-23 Thread no-reply
Forum: CFEngine Help
Subject: Re: Starting cf-execd from inittab
Author: aleksey_c
Link to topic: https://cfengine.com/forum/read.php?3,27509,27511#msg-27511

For respawn to work correctly, processes should not fork themselves. The 
respawn attribute is associated with the parent process that is started by 
init, not the forked child processes.

___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


CFEngine Help: Re: Starting cf-execd from inittab

2012-09-23 Thread no-reply
Forum: CFEngine Help
Subject: Re: Starting cf-execd from inittab
Author: aleksey_c
Link to topic: https://cfengine.com/forum/read.php?3,27509,27512#msg-27512

I've seen a few examples of how to make sure that cf-execd is always running. 
Most of them include cron job regulary starting shell script. But init respawn 
solution looks more elegant. So, I configured few servers to run cf-execd that 
way. At least it works. But I want to know are there any potential problems? 
Maybe someone already using respawn?

___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


CFEngine Help: Re: Starting cf-execd from inittab

2012-09-23 Thread no-reply
Forum: CFEngine Help
Subject: Re: Starting cf-execd from inittab
Author: aleksey_c
Link to topic: https://cfengine.com/forum/read.php?3,27509,27513#msg-27513

Just looked at the source code of cfengine-3.3.5\src\cf-execd.c

When starting cf-execd with --nofork or -F option ONCE flag is set to true

case 'F':
ONCE = true;
NO_FORK = true;
break;


So, cf-execd does not start an infinite loop and exit after every execution.

if (ONCE)
{
CfOut(cf_verbose, "", "Sleeping for splaytime %d seconds\n\n", 
SPLAYTIME);
sleep(SPLAYTIME);
LocalExec(&config);
CloseLog();
}
else
{
while (true)
{
if (ScheduleRun())
{
CfOut(cf_verbose, "", "Sleeping for splaytime %d seconds\n\n", 
SPLAYTIME);
sleep(SPLAYTIME);

#if defined(HAVE_PTHREAD)
if (!LocalExecInThread(&config))
{
CfOut(cf_inform, "", "Unable to run agent in thread, 
falling back to blocking execution");
#endif
LocalExec(&config);
#if defined(HAVE_PTHREAD)
}
#endif
}
}
}


Of course init restarts the process but it is disrupts the normal cycle of the 
program. Therefore at the moment it is not possible to use init respawn :( 
Seems like it is possible to make small changes to the code of cf-execd.c to 
support running from init. For example, separate option --once or -O.

Can I request a feature?

___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


a small (aesthetic) bug in set_variable_values bundle

2012-09-23 Thread Aleksey Tsalolikhin
Hi,

  May I show you a modified set_variable_values bundle?
This came out of one of my classes.

  The main difference is you won't get lines like "name =value2"
if you start with "name = value1".  (Note the asymetrical space
around the equals sign.)  Instead you get lines like "name=value2".

  It was a useful class exercise, that's for sure.  I'm not sure if it'd
be useful to the broader community, or worth suggesting an update
to the COPBL.

  BTW, props to Diego for set_variable_values, it is very useful!  We
are just building on his work a little bit.  Like I said, I'm not sure if
this might of interest/use to you?

bundle edit_line set_variable_values__symmetrical(v)

# The main difference from set_variable_values is that
# you won't get lines like "name =value2" if you start with
# "name = value1".  (Note the asymetrical space around
# the equals sign.)  Instead you get lines like "name=value2".

{
  vars:

  "index" slist => getindices("$(v)");

  field_edits:

  # match a line starting like the key *BLANK SPACE* = something

  "\s*$(index)\s+=.*"

   edit_field => col("=","1","$(index)","set"),
hitespace otherwise our insert_lines promise would create a duplicate
name=value entry WITHOUT whitespace.";

  # match a line starting like the key = something

  "\s*$(index)=.*"

   edit_field => col("=","2","$($(v)[$(index)])","set"),
espace after the equals sign.";

  insert_lines:

  "$(index)=$($(v)[$(index)])",

  comment => "Insert name=value definition";
}
}}}
___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


Re: a small (aesthetic) bug in set_variable_values bundle

2012-09-23 Thread Diego Zamboni
Hey Aleksey,

Thanks for the contribution! Definitely, if you think it's worth the update, 
please submit a pull request to the copbl repository on github: 
http://github.com/cfengine/copbl/

Also, thanks for the kind words, but set_variable_values was not written by me, 
it was there before :) We are always definitely interested in ways of improving 
the stdlib.

Cheers,
--Diego


On Sep 23, 2012, at 8:33 PM, Aleksey Tsalolikhin  
wrote:

> Hi,
> 
>  May I show you a modified set_variable_values bundle?
> This came out of one of my classes.
> 
>  The main difference is you won't get lines like "name =value2"
> if you start with "name = value1".  (Note the asymetrical space
> around the equals sign.)  Instead you get lines like "name=value2".
> 
>  It was a useful class exercise, that's for sure.  I'm not sure if it'd
> be useful to the broader community, or worth suggesting an update
> to the COPBL.
> 
>  BTW, props to Diego for set_variable_values, it is very useful!  We
> are just building on his work a little bit.  Like I said, I'm not sure if
> this might of interest/use to you?
> 
> bundle edit_line set_variable_values__symmetrical(v)
> 
> # The main difference from set_variable_values is that
> # you won't get lines like "name =value2" if you start with
> # "name = value1".  (Note the asymetrical space around
> # the equals sign.)  Instead you get lines like "name=value2".
> 
> {
>  vars:
> 
>  "index" slist => getindices("$(v)");
> 
>  field_edits:
> 
>  # match a line starting like the key *BLANK SPACE* = something
> 
>  "\s*$(index)\s+=.*"
> 
>   edit_field => col("=","1","$(index)","set"),
> hitespace otherwise our insert_lines promise would create a duplicate
> name=value entry WITHOUT whitespace.";
> 
>  # match a line starting like the key = something
> 
>  "\s*$(index)=.*"
> 
>   edit_field => col("=","2","$($(v)[$(index)])","set"),
> espace after the equals sign.";
> 
>  insert_lines:
> 
>  "$(index)=$($(v)[$(index)])",
> 
>  comment => "Insert name=value definition";
> }
> }}}
> ___
> Help-cfengine mailing list
> Help-cfengine@cfengine.org
> https://cfengine.org/mailman/listinfo/help-cfengine

___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


Re: a small (aesthetic) bug in set_variable_values bundle

2012-09-23 Thread Aleksey Tsalolikhin
On Sun, Sep 23, 2012 at 7:30 PM, Diego Zamboni  wrote:
> Hey Aleksey,
>
> Thanks for the contribution! Definitely, if you think it's worth the update, 
> please submit a pull request to the copbl repository on github: 
> http://github.com/cfengine/copbl/

Pull request sent.

> Also, thanks for the kind words, but set_variable_values was not written by 
> me, it was there before :) We are always definitely interested in ways of 
> improving the stdlib.

Oops.  My apologies to the original author.  Thank you, Diego!

Yours fondly,
Aleksey
___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


Re: CFEngine Help: Re: Starting cf-execd from inittab

2012-09-23 Thread Aleksey Tsalolikhin
> Of course init restarts the process but it is disrupts the normal cycle of 
> the program. Therefore at the moment it is not possible to use init respawn 
> :( Seems like it is possible to make small changes to the code of cf-execd.c 
> to support running from init. For example, separate option --once or -O.
>
> Can I request a feature?

I like the idea of running cf-execd out of inittab.

We had crond die on one of our servers last Friday.  That server runs
CFEngine from cron, so CFEngine stopped running.  Would have been nice
to have init kick off CFEngine which would have restarted crond.

Best,
-at
___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


CFEngine Help: auto-scrolling website

2012-09-23 Thread no-reply
Forum: CFEngine Help
Subject: auto-scrolling website
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,27522,27522#msg-27522

Before I go to the new bug site, I'm curious.  Am I the only person being 
driven absolutely insane by the inability to scroll on the reference manual 
page after clicking on an anchor link?  My workflow with the reference manual 
is "push the home button on my keyboard", "scroll down to the appropriate 
'bundles of X' section", and progressively drill down to what I'm looking for.  
But for the last few months, scrolling down from the top of the page hits some 
trigger that "helpfully" scrolls me back to the location of anchor in the URL 
bar.  Sometimes my workstation is just slow enough to process that so my mouse 
almost gets to the link I want to click before the page moves out from under 
me, which I'm sure is great fun for the ears of people who sit near me. :)

But anyway, I'm curious if the behavior is just something about being me, or if 
this was an intentional user interface failure.

___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


Re: CFEngine Help: Re: False report of "no constrants" in constrained classes promises.

2012-09-23 Thread Aleksey Tsalolikhin
Dear Mark,

  Thanks for your kind reply.

On Sun, Sep 23, 2012 at 12:46 AM,  Mark Burgess wrote:
>> The body of a promise details and constrains its nature.  This promise
>> is constrained by the ifvarclass attribute.
>
> That's true but there are no constraints that determine the class.

I still don't get it.  Doesn't the context constrain the promise?  the
ifvarclass
will evaluate to true on some systems and false on others.

Let me come at it from another angle.  Could you please explain why
this is valid:

{{{
bundle agent example
{
  classes:
  "solinux"
  comment => "Set a custom class based on built-in classes",
   expression => "linux|solaris";
}
}}}

but the following isn't?

{{{
bundle agent example
{
  classes:
linux|solaris::
  "solinux";
}
}}}

In both cases I want to create a custom class based on nothing else
but an evaluation of the current environment as compared to a class
expression.  Why is promise body required, please?

> I think what you are trying to write is this ...

Yes, thank you very much!!

Please do answer the above.

Yours fondly,
Aleksey
___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


CFEngine 3.3.5 does not like {{{ classes: "webclass" or => { "@(webservers)" }; }}} (Was: Re: CFEngine Help: Re: False report of "no constrants" in constrained classes promises.)

2012-09-23 Thread Aleksey Tsalolikhin
On Sun, Sep 23, 2012 at 12:46 AM,  Mark wrote:
>
> I think what you are trying to write is this:
>
>
> vars:
> "webservers" slist => { "web01", "web02", "web03" };
>
> classes:
>
>"webclass" or => { "@(webservers)" };

Dear Mark,

  I tried the above, and it works standalone, but when I tried to
integrate it into Neil Watson's dynamic bundlesequence example
(http://watson-wilson.ca/2011/09/dynamic-bundlesequence-in-cfengine.html)
I got: Unable to parse class expression: ->@(webservers)

This is with 3.3.5.  Please advise?


[root@web01 
370-0010_Dynamic_Bundlesequence.__demo_of_dynamic_inputs_and_bundleseq]#
cf-agent -f ./main.cf -K
Unable to parse class expression: ->@(webservers)
Bundle "httpd" listed in the bundlesequence is not a defined bundle
Bundle "proxy" listed in the bundlesequence is not a defined bundle
Fatal CFEngine error: Errors in promise bundles
cf-agent was not able to get confirmation of promises from
cf-promises, so going to failsafe
[root@web01 
370-0010_Dynamic_Bundlesequence.__demo_of_dynamic_inputs_and_bundleseq]#
more main.cf site ntp httpd proxy db2 mysql
::
main.cf
::

bundle common global_classes {

   classes:
   "cf_dbs"
   expression => "linux";


vars:
"webservers" slist => { "web01", "web02", "web03" };

classes:

   "cf_webfarm" or => { "@(webservers)" };
}


bundle common global_vars {
vars:

any::

"bseq" slist => {
"site",
"ntp",
},
policy => "overridable";

cf_dbs::

"bseq" slist => {
@{bseq},
"db2",
"mysql"
},
policy => "overridable";

cf_webfarm::

"bseq" slist => {
@{bseq},
"httpd",
"proxy"
},
policy => "overridable";
}

body common control {

inputs => { @{global_vars.bseq} };
bundlesequence => { @{global_vars.bseq} };

}
::
site
::
bundle agent site{
reports:
cfengine_3::
"site bundle";
}
::
ntp
::
bundle agent ntp{
reports:
cfengine_3::
"ntp bundle";
}
::
httpd
::
bundle agent httpd{
reports:
cfengine_3::
"httpd bundle";
}
::
proxy
::
bundle agent proxy{
reports:
cfengine_3::
"proxy bundle";
}
::
db2
::
bundle agent db2{
reports:
cfengine_3::
"db2 bundle";
}
::
mysql
::
bundle agent mysql{
reports:
cfengine_3::
"mysql bundle";
}
[root@web01 
370-0010_Dynamic_Bundlesequence.__demo_of_dynamic_inputs_and_bundleseq]#
___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


CFEngine Help: Re: allclasses facility?

2012-09-23 Thread no-reply
Forum: CFEngine Help
Subject: Re: allclasses facility?
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,27436,27524#msg-27524

neilhwatson Wrote:
---
> What other facility is there to get a list of all
> defined classes?

You're probably supposed to parse the allclasses environment variable (which is 
mentioned only once in the reference manual, which isn't clearly an environment 
variable of CFEngine array, and whose format seems to be undocumented either 
way), until that gets inconvenient, at which time I guess you are expected to 
redesign things to make that more convenient. :)


These variables end up in a context which has the same name as the module. When 
the $(allclasses) variable becomes too large to manipulate conveniently, you 
can access the complete list of currently defined classes in the file 
/var/cfengine/state/allclasses. 


Of course, I don't see that variable in CFEngine or in the environment:


sauer@host
$ cat test.cf
bundle agent a{
commands:
  "/usr/bin/pcregrep -oi 'allclass[^[:cntrl:]]+' /proc/self/environ"
module => "true";
reports:
  cfengine:: "$(allclasses)";
}
sauer@host
$ cf-agent -f ./test.cf -b a -IK
 >> Using command line specified bundlesequence
 -> Executing '/usr/bin/pcregrep -oi 'allclass[^[:cntrl:]]+' 
/proc/self/environ' ...(timeout=-678,owner=-1,group=-1)
 !! Finished command related to promiser "/usr/bin/pcregrep -oi 
'allclass[^[:cntrl:]]+' /proc/self/environ" -- an error occurred (returned 1)
 -> Completed execution of /usr/bin/pcregrep -oi 'allclass[^[:cntrl:]]+' 
/proc/self/environ
R: $(allclasses)


FYI...
On Linux, /proc//environ contains all of 's environment variables, separated by 
null characters, /proc/self is "whatever process is accessing it", and 
"pcregrep or grep -o" prints only the part of the line that matches.  Just in 
case that pcregrep command doesn't make any sense (it really does work, 
though). ;)


sauer@host
$ /usr/bin/pcregrep -oi 'shell[^[:cntrl:]]+' /proc/self/environ
SHELL=/usr/bin/sh


As an aside, "pcregrep -oi '[[:cntrl:]]?[^[:cntrl:]]*ass[^[:cntrl:]]+' 
/proc/*/environ" as root is a fun way to find people who think that they're 
being secure / clever by setting $PASSWORD environment variables instead of 
passing them on the command line.  Yay security!

___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine


CFEngine Help: Re: False report of "no constrants" in constrained classes promises.

2012-09-23 Thread no-reply
Forum: CFEngine Help
Subject: Re: False report of "no constrants" in constrained classes promises.
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,27501,27526#msg-27526

There's no action for a classes promise with nothing in the body but an 
"ifvarclass" because of the way ifvarclass is evaluated.  A classes promise 
sets the class if the action in the body is true - but there is no action to 
observe.  You've asked Schrodinger's cat to decide whether or not the class 
should be set. :)

Mark's "or" suggestion is probably more efficient in this case, but if you must 
use "ifvarclass" for whatever reason (I can think of a couple), you can stick 
an or => { "any" } in there so that there's an action; a "thing to do".

___
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine