Search code examples
validationvariablespuppet

Puppet validate lookup of ip address with port eg 1.2.3.4:5678


I am performing a lookup as a top scope variable in a Puppet manifest for values that will contain a concatenated IP address and port, e.g., 1.2.3.4:5678.

I know that I can do validation on either IP address OR port with the following:

Stdlib::IP::Address::V4 $server = lookup(profiles::something::server)

or

Stdlib::Port $server = lookup(profiles::something::server)

however, I want to validate both together, for example

String[[Stdlib::IP::Address::V4]:[Stdlib::Port]] $server = lookup(profiles::something::server)

However, I cannot find a way other than splitting them in the manifest and performing in-line validation.

Is there a way to do a combined lookup validation of a top-scope variable?


Solution

  • The approach you show for validating the form of the value relies on data type aliases defined in the puppetlabs-stdlib module. If there is no suitable alias there for what you want then you can always write a full type expression for what you want. In that event, I would recommend also defining a type alias for that in some module under your control, as a suitable alias name is much easier to comprehend than a complex type expression. You could look at the type aliases defined in stdlib to help get yourself going.