Ask Your Question

Revision history [back]

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

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 ") } } } } }

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

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 ") } } } } }