开发者

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开发者_JAVA百科 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜