if facter variable exists it works ---but if the facter does not exist i get Warning: Unknown variable: '...'

asked 2018-02-22 06:12:43 -0600

naftuli gravatar image

updated 2018-02-22 06:15:24 -0600

Puppet version 3.8 ( I know its old but its what we have)

I have some code that works fine when the facter exists , but if the facter does not exist i get Warning: Unknown variable: 'monitoring'

But we have a situation where this facter may not exist on some servers and thus the puppet run will fail ... unless we do this "strict_variables = warn", but this isnt ideal.

Ive tried with all three options below and the code runs but I get

Warning: Unknown variable: 'monitoring'

Can anyone suggest how I can run the case statement only if the variable is declared, and if its not , just ignore the case.

if $monitoring {

case $monitoring { /P[1-3]/: { case $environment { 'CI', 'QA', 'STATIC-CI': { notice("Welcome to ZABBIX install ") } } } } }

if defined($monitoring) {

case $monitoring { /P[1-3]/: { case $environment { 'CI', 'QA', 'STATIC-CI': { notice("Welcome to ZABBIX install ") } } } } }

if $monitoring == undef {

case $monitoring { /P[1-3]/: { case $environment { 'CI', 'QA', 'STATIC-CI': { notice("Welcome to ZABBIX install ") } } } } }

edit retag flag offensive close merge delete

Comments

That was one of the changes that makes your code semantically safer, but adds a little bit of extra bloat in the change from 3.x to 4+, and You are probably using a version with 'strict variable' setting enabled. I believe that you could use 'if defined($monitoring)' instead of 'if $monitoring'

DarylW gravatar imageDarylW ( 2018-02-23 08:51:28 -0600 )edit