# how do I check if a fact is defined?

Some of my modules are checking if a fact is defined, for example:

if($::eyp_docker_iscontainer!=undef) { ... }  In puppet 4.4.2 I get this warning: Warning: Undefined variable 'eyp_docker_iscontainer'; (file & line not available)  how do I check if a fact is defined without getting this warning? thanks edit retag close merge delete ## 1 Answer Sort by » oldest newest most voted Try this if defined('$::eyp_docker_iscontainer') {
...
}


Or if you have stdlib available:

if has_key($facts, 'eyp_docker_iscontainer') { ... }  In Puppet 4, as a point of style, use of the$facts hash is preferred, see here.

more

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

## Stats

Asked: 2016-05-04 11:11:47 -0600

Seen: 3,701 times

Last updated: May 04 '16