- Mastering Puppet 5
- Ryan Russell Yates Jason Southgate
- 55字
- 2021-07-16 17:46:16
Checking the input value with a validate block
We can validate the provided value of a new property called version with a validate block and, for example, a regex expression, as shown in the following code:
Puppet::Type.newtype(:mynewtype) do
...
newproperty(:version) do
validate do |value|
fail("Invalid version specified") unless value =~
/^(\d+\.)?(\d+\.)?(\*|\d+)$/
end
end
...
end