Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to "assert" in Puppet?

Is there a way to assert that a variable (or more specifically, a fact) in puppet has a particular value, and to abort the installation if it doesn't?

For background, here is the situation:

In most cases I can refer to hostnames, but sometimes I need to use an IP address. For example, our log collector host needs to open a port in the firewall for several specific machines (and not a whole subnet). I need to use IP addresses to open a hole in the firewall. Since the IP addresses of machines don't change, I was planning on encoding the IP address as part of the configuration, but I'd like to check on the individual hosts that the actual IP address matches the one in its configuration and fail if it doesn't. Is that possible?

like image 932
Joe Shaw Avatar asked Sep 27 '11 14:09

Joe Shaw


1 Answers

I believe something like this would work:

if $ipaddress != $expectedipaddress {
  fail("IP mismatch")
}

The fail() function causes a parse failure. Wrapping it in a conditional should get the assert behavior you want.

I haven't tested this specific usage, but if parsing fails a new catalog isn't compiled and the client doesn't get anything.

like image 120
freiheit Avatar answered Nov 13 '22 09:11

freiheit