Ask Your Question

is there a way to ask puppet, not to compile further code if value does not exists ?

asked 2015-05-08 12:30:38 -0600

k2patel gravatar image

updated 2015-05-08 18:03:23 -0600

JohnsonEarls gravatar image

i'm looking help to understand what i'm doing wrong
my code is -
i have two custom facter lib - hiera values - and iteration using future parser
it works just fine if user web exists
but it fails and dont compile manifest if user web does not exists
is there a way to ask puppet, not to compile further code if value does not exists ?

Adding more context -

Hiera entry is always going to be there, but it is failing on following

$piston1 = "user_home_${sec_user}"
$scdirectory = inline_template("<%= eval('${piston1}') %>")

with following error -

Could not find value for 'user_home_lrknox'

piston1=user_home_lrknox ( which is facter value """" only if user lrknox exists on system """")

But eval is giving error as that fact does not exists, As puppet suppose to create that user.
I've tried to specify dependency but that doesn't helped.
so while compiling manifest it says user does not exists but well ..... i guess that gives idea.

There might be better way to do this.
I'm trying to create second user with same uid / gid as primary user.
and based on primary username puppet should get it's UID / GID / Home and replicate the user.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-05-08 15:32:45 -0600

JohnsonEarls gravatar image

updated 2015-05-08 18:09:11 -0600

So you are trying to create secondary accounts for users who may or may not exist on the system.

Since the user_home_username fact may not exist, try this:

$piston1 = "user_home_${sec_user}"
if defined("\$${piston1}") {
    $scdirectory = inline_template("<%= eval('${piston1}') %>")
    if $scuserid {
edit flag offensive delete link more


That worked, didn't know you can use method defined, neither accessing value with \$$

k2patel gravatar imagek2patel ( 2015-05-11 12:24:58 -0600 )edit

The `defined` function takes a string which represents a variable reference (i.e. `defined('$foo')` to check if $foo is defined). In your case, the variable name is specified by another variable, so you use `""` instead of `''` and include a `\$` to make sure you get `$` before the variable name.

JohnsonEarls gravatar imageJohnsonEarls ( 2015-05-11 13:00:28 -0600 )edit

Thank you.

k2patel gravatar imagek2patel ( 2015-05-12 10:25:27 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-05-08 12:30:38 -0600

Seen: 220 times

Last updated: May 08 '15