1

I'm trying to add a 'type' layer to our hiera backend so webservers can get common configuration, databases get some common configuration, etc.

Our hostname scheme is [env][number].domain.tld

where [env] and [number] are optional. [env] can be one of prod, stage, dev, or test. [number] is any digit 0-9.

I'm trying to extract from the hostname and using that in hiera.

This is what I'm using to set the global $hosttype in puppet: $hosttype = regsubst($fqdn, '(.+?)(?=(dev)|(stg)|(test)|(prod)|(\d)|(\.))', '\1')

This retrieves the fqdn, not just the . The regex works in rubular.com, but puppet 4.10 is on ruby 2.1.x and rubular is on 2.5.7. I'm new to puppet, thanks for the patience.

6
  • 1
    According to me your Q&A is more on-topic on DevOps SE. SO and SF are about software and system engineering respectively. Commented Dec 31, 2019 at 21:38
  • Its stack exchanges all the way down isn't it. Commented Dec 31, 2019 at 22:17
  • Could you show us sample input / expected output? Rubular.com supports permalink -- maybe include that in your question. Commented Jan 8, 2020 at 17:25
  • You want just dev1 from wwwdev1.example.com? Try regsubst($fqdn, '(.+?)(((dev)|(stg)|(test)|(prod))(\\d))\..+', '\2'). I have no idea if that's the most efficient way or not.. Commented Jan 8, 2020 at 17:53
  • I want www from that url. Example: rubular.com/r/ZxVYhekuzfG6dL Commented Jan 9, 2020 at 21:15

0

You must log in to answer this question.