A question from Wolfgang in #CFEngine:matrix.org
I’m confused. I have a bundle that should only run on one specific host. What confuses me is that CFE tries to evaluate the variables. In that bundle, I have something like “uid” int => getuid(“my-user”), but of course this user does not exist on the other systems. However, cfe shows an error saying that it could not get the uid for that user.
CFEngine is eager to resolve variables (classes in common bundles too), for more read about pre-evaluation.
Get the UID of a user, but only if the user exists as a local user on the system.
bundle agent main
{
vars:
"i" int => getuid( "no-such-user" );
"j" int => getuid( "nickanderson" );
}
error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found) error: Could not get UID for user 'no-such-user', (getpwnam: not found)
bundle agent main
{
vars:
"filter" slist => { "name=no-such-user" };
"i"
int => getuid( "no-such-user" ),
if => isgreaterthan( length( getindices( findlocalusers( "@(filter)" ) ) ), 0 );
"filter" slist => { "name=nickanderson" };
"j" int => getuid( "nickanderson" ),
if => isgreaterthan( length( getindices( findlocalusers( "@(filter)" ) ) ), 0 );
reports:
"i = $(i)";
"j = $(j)";
}
R: j = 1000 R: i = $(i)