nerabis
nerabis

Reputation: 25

replace variable value on ruby template via puppet

I am looking the way to have the result of this ruby template file:

ServerName 1.server.foo

knowing that if I run

$ facter -p fqdn
1.server.foo.internet.com

I would probably play with <%= @fqdn %> and .gsub?

server-id: <%= @fqdn %>.gsub(/.internet.com/, '')

Upvotes: 0

Views: 1802

Answers (2)

Jon
Jon

Reputation: 3671

The entire expression needs to be in the <%= %> tag, so try

server-id: <%= @fqdn.regsubst(/.internet.com/, '') %>

The template syntax is documented at https://puppet.com/docs/puppet/5.5/lang_template_erb.html with examples of expressions used in <%= %> tags.

I'd also note that ERB templates have been replaced by native Embedded Puppet EPP templates, so it may be better to convert now.

Upvotes: 2

nerabis
nerabis

Reputation: 25

using EPP with regsubst it works!

server-id: <%= $facts[fqdn].regsubst(/.internet.com/, '') %>

Upvotes: 0

Related Questions