Ask Your Question
2

how to check if fact exists in manifest file?

asked 2014-02-04 09:17:37 -0500

sysadmin gravatar image

Hi,

Can someone tell me how to check if fact exists and not null on system within the manifest file?

Thanks

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
2

answered 2014-02-04 09:28:29 -0500

doc75 gravatar image

I would do it like that:

if $factname != undef {
  ...
} else {
  ...
}

Hope this helps.

edit flag offensive delete link more

Comments

if $ipaddress_eth0 != undef { template... } I'm getting this error: "error: could not parse for environment production: syntax error at ipaddress_eth0'; expected } at ...."

sysadmin gravatar imagesysadmin ( 2014-02-05 00:11:59 -0500 )edit

Could you please post your code somewhere. I am not sure but this it probably not related to this way of doing.

doc75 gravatar imagedoc75 ( 2014-02-05 04:07:43 -0500 )edit

There's also the the “defined” function https://docs.puppet.com/puppet/latest/reference/function.html#defined .

Kai Burghardt gravatar imageKai Burghardt ( 2016-11-07 08:06:39 -0500 )edit
0

answered 2016-11-03 08:53:20 -0500

AmberW gravatar image

This question is a bit old but I found it before I found the answer. Hope this helps!

https://docs.puppet.com/puppet/latest...

if $facts['is_virtual'] {
  warning('Tried to include class ntp on virtual machine; this node may be misclassified.')
}
elsif $facts['os']['family'] == 'Darwin' {
  warning('This NTP module does not yet work on our Mac laptops.')
}
else {
  include ntp
}
edit flag offensive delete link more
-1

answered 2015-11-18 21:18:21 -0500

zsl gravatar image
if $fact {
 notify { "fact exists":}
}

Do not use$::fact or ${::fact} when you do this kind of testing. Everything will be just fine.

edit flag offensive delete link more

Comments

Explain (reasons).

Kai Burghardt gravatar imageKai Burghardt ( 2016-11-07 08:05:47 -0500 )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

Stats

Asked: 2014-02-04 09:17:37 -0500

Seen: 6,536 times

Last updated: Nov 03 '16