Ask Your Question
0

How to get hiera to output the literal string '%{::fqdn}'?

asked 2017-03-24 13:36:16 -0500

Red Cricket gravatar image

I would like to know what I would need to have in my yaml file to have hiera output the literal string %{::fqdn} instead of outputting the value of the puppet fact fqdn.

Here is what I have tried.

# grep foo::p4 /etc/puppetlabs/code/environments/production/hieradata/bar.yaml
foo::p4: 'http://%{hiera(''p1'')}/%{::fqdn}'

And this is the result:

# hiera foo::p4 '::prefix_fact=bar' '::fqdn=thing.com' environment=production
http://test/thing.com

What I actually want the output to be is:

http://%{hiera('p1')}/%{::fqdn}

I guess I could do something goofy like this:

p1: 'test'
pa: '%{hiera'
pb: '("p1")}'
pc: '%{::fq'
pd: 'dn}'
foo::p4: "%{hiera('pa')}%{hiera('pb')}%{hiera('pc')}%{hiera('pd')}"

Then the output is what I want:

# hiera foo::p4 '::prefix=bar' '::fqdn=thing.com' environment=production
%{hiera("p1")}%{::fqdn}
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2017-03-27 07:17:53 -0500

DarylW gravatar image

I believe you are looking for https://docs.puppet.com/puppet/4.9/hi...

Youwould want is something like this

foo::p4: 'http://%{hiera(p1)}/%{literal('%')}{::fqdn}'

From the docs...

literal

The literal interpolation function lets you escape a literal percent sign (%) in Hiera data, to avoid triggering interpolation where it isn’t wanted. This is useful when you’re dealing with things like Apache config files, which might include text like %{SERVER_NAME}.

For example: server_name_string: "%{literal('%')}{SERVER_NAME}"

The value of server_name_string would be %{SERVER_NAME}, and Hiera would not attempt to interpolate a variable named SERVER_NAME.

The only legal argument for literal is a single % sign.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-03-24 13:36:16 -0500

Seen: 53 times

Last updated: Mar 27