Puppet 5 Stdlib IP address parsing

224 views
Skip to first unread message

John Baird

unread,
Feb 14, 2018, 7:41:01 PM2/14/18
to Puppet Users

According to the stdlib docs, "is_ip_address" is deprecated.  There is no mention of how to replace it without using "validate_legacy" which itself will ultimately be deprecated.

Is there a better/proper approach to validating IPv4 and/or IPv6 syntax with Puppet 5 ?
`

is_ip_address

Deprecated. Will be removed in a future version of stdlib. See validate_legacy.

Returns true if the string passed to this function is a valid IP address.

Type: rvalue.

`

R.I. Pienaar

unread,
Feb 15, 2018, 1:19:30 AM2/15/18
to puppet...@googlegroups.com
Use the Stdlib::Compat::Ipv4, ::Ipv6 and ::Ip_address data types 

---
R.I.Pienaar
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/3275659c-d7c0-487f-979b-8e62da5a3cd1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Baird

unread,
Feb 15, 2018, 8:50:49 AM2/15/18
to Puppet Users
R.I,

Can you point me to some docs on exactly how to use those?  I have looked and I only see references to using them, but not how to actually use them within a manifest for validation.  Any places you can point me to would be much appreciated!

Also, thanks for all of the useful modules you have written over the years, I recognized your name instantly!  Thanks for getting back to me!

John Baird

R.I.Pienaar

unread,
Feb 15, 2018, 9:01:57 AM2/15/18
to puppet...@googlegroups.com


On Thu, 15 Feb 2018, at 14:50, John Baird wrote:
> R.I,
>
> Can you point me to some docs on exactly how to use those? I have looked
> and I only see references to using them, but not how to actually use them
> within a manifest for validation. Any places you can point me to would be
> much appreciated!

class thing(
Stdlib::Compat::Ipv4 $ipaddress
) {

}

this is how you tell it the class param has to be a ipv4, any attempt to pass anything else is a compile error

https://puppet.com/docs/puppet/5.3/lang_data_type.html

>
> Also, thanks for all of the useful modules you have written over the years,
> I recognized your name instantly! Thanks for getting back to me!
>
> John Baird
>
> On Thursday, February 15, 2018 at 12:19:30 AM UTC-6, R.I. Pienaar wrote:
> >
> > Use the Stdlib::Compat::Ipv4, ::Ipv6 and ::Ip_address data types
> >
> > ---
> > R.I.Pienaar
> >
> > On 15 Feb 2018, at 01:41, John Baird <john.w...@gmail.com <javascript:>>
> > wrote:
> >
> >
> > According to the stdlib docs, "is_ip_address" is deprecated. There is no
> > mention of how to replace it without using "validate_legacy" which itself
> > will ultimately be deprecated.
> >
> > Is there a better/proper approach to validating IPv4 and/or IPv6 syntax
> > with Puppet 5 ?
> > `
> > is_ip_address
> >
> > *Deprecated. Will be removed in a future version of stdlib.
> > See validate_legacy
> > <https://forge.puppet.com/puppetlabs/stdlib#validate_legacy>.*
> >
> > Returns true if the string passed to this function is a valid IP address.
> >
> > *Type*: rvalue.
> >
> > `
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Puppet Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to puppet-users...@googlegroups.com <javascript:>.
> > <https://groups.google.com/d/msgid/puppet-users/3275659c-d7c0-487f-979b-8e62da5a3cd1%40googlegroups.com?utm_medium=email&utm_source=footer>
> > .
> > For more options, visit https://groups.google.com/d/optout.
> >
> >
>
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/273e4a69-f25a-4261-8bfd-25ff8cc74d6e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


--
R.I.Pienaar / www.devco.net / @ripienaar

John Baird

unread,
Feb 15, 2018, 9:02:44 AM2/15/18
to Puppet Users
Ok, that works.  I appreciate the response, thanks!

John Baird

unread,
Feb 15, 2018, 9:04:44 AM2/15/18
to Puppet Users
Do you have any recommendations for validating a custom top-scope fact?  Meaning, it's not a module scope, how can I verify a top-scope variable if I can't put that in the class params?

R.I. Pienaar

unread,
Feb 16, 2018, 1:02:47 AM2/16/18
to puppet...@googlegroups.com

On 15 Feb 2018, at 15:04, John Baird <john.w...@gmail.com> wrote:

Do you have any recommendations for validating a custom top-scope fact?  Meaning, it's not a module scope, how can I verify a top-scope variable if I can't put that in the class params?

unless $facts[“whatever”] =~ Stdlib::Compat::Ipv4 {
  fail(“meh”)
}

Though I would say your class should have a ip parameter and callers should supply the value and you should if but perhaps default so the fact this will help with tests etc

class whatever(Stdlib::Compat::Ipv4 $ip = $facts[“whatever”]) { }

This will help with tests too 


R.I. Pienaar

unread,
Feb 16, 2018, 1:04:32 AM2/16/18
to puppet...@googlegroups.com


On 16 Feb 2018, at 07:02, R.I. Pienaar <r...@devco.net> wrote:


On 15 Feb 2018, at 15:04, John Baird <john.w...@gmail.com> wrote:

Do you have any recommendations for validating a custom top-scope fact?  Meaning, it's not a module scope, how can I verify a top-scope variable if I can't put that in the class params?

unless $facts[“whatever”] =~ Stdlib::Compat::Ipv4 {
  fail(“meh”)
}

Though I would say your class should have a ip parameter and callers should supply the value and you should if but perhaps default so the fact this will help with tests etc

Wow terrible sentence - hope it’s clear. Mobile phones don’t help with sending code snippets etc :)


Reply all
Reply to author
Forward
0 new messages