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.

  • 1
    According to me your Q&A is more on-topic on [DevOps SE](https://devops.stackexchange.com/questions). SO and SF are about software and system engineering respectively. – 030 Dec 31 '19 at 21:38
  • Its stack exchanges all the way down isn't it. –  Dec 31 '19 at 22:17
  • Could you show us sample input / expected output? Rubular.com supports permalink -- maybe include that in your question. – Aaron Copley Jan 08 '20 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.. – Aaron Copley Jan 08 '20 at 17:53
  • I want www from that url. Example: https://rubular.com/r/ZxVYhekuzfG6dL –  Jan 09 '20 at 21:15
  • You might want to extract the values from the hostname with a custom fact, then you can re-use them in multiple places: https://puppet.com/docs/facter/3.6/fact_overview.html – jrtapsell May 25 '20 at 21:20

0 Answers0