Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top