Puppet how to tell if a variable is set -
in puppet class how should test if variable has been set or not? right checking if variable undefined:
if $http_port != undef { $run_command = "$run_command --http-port $http_port" }
is there better way check if variable has been declared or not?
if testing if vaiable undef, way correct. writing
if $http_port { $run_command = "$run_command --http-port $http_port" }
would accomplish same. if $http_port undef of false, not run command.
if want test if var has been definded should do:
if defined($http_port) { $run_command = "$run_command --http-port $http_port" }
see https://docs.puppet.com/puppet/4.10/function.html#defined.
if var class variable like:
class your_class ( optional[integer[0, 65535]] $http_port = undef, ) { if $http_port { notify { "got here http_port=${http_port}": } } }
it run notify if class declared http_port set integer between 0 , 65535.
Comments
Post a Comment