Ask Your Question
0

Facts in EPP not working

asked 2017-04-26 17:31:17 -0500

wsanders1 gravatar image

updated 2017-04-26 18:10:11 -0500

I am trying to get an EPP template working with facter facts. I am cut and pasting the example directly from the "Expression-printing tags" section of https://docs.puppet.com/puppet/4.10/lang_template_epp.html and getting null data:

$ cat /tmp/foo.epp
ServerName <%= $fqdn %>

and I get

$  puppet epp render /tmp/foo.epp
ServerName

Ppuppet client version is 4.5.2. What am I doing wrong? Thanks, -w

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2017-04-27 12:22:13 -0500

wsanders1 gravatar image

updated 2017-05-02 13:08:17 -0500

This turns out to be dependent on the version of puppet you are running. These examples are using puppet 4.3.1, which although quite old is what I am stuck with on this particular client.

This does not work:

// EPP TEST: // bindmaster = "bindmaster1.<%= $::fqdn %>"

>     Error: Could not retrieve catalog from remote server: Error 500 on
> SERVER: Internal Server Error:
> org.jruby.exceptions.RaiseException:
> (SyntaxError)
> /etc/puppetlabs/code/environments/production/modules/profiles/templates/namedresolver.conf:4:
> syntax error, unexpected ':'
>     ; _erbout.concat(( $::fqdn ).to_s); _erbout.concat "\"\n//
> bindmaster = \"bindmaster1."

This does not work:

-// bindmaster = "bindmaster1.<%= @['fqdn'] %>"

>     Error: Could not retrieve catalog from remote server: Error 500 on
> SERVER: Internal Server Error:
> org.jruby.exceptions.RaiseException:
> (SyntaxError)
> /etc/puppetlabs/code/environments/production/modules/profiles/templates/namedresolver.conf:4:
> syntax error, unexpected null
>     ; _erbout.concat(( @['fqdn'] ).to_s); _erbout.concat "\"\n//
> bindmaster = \"bindmaster1."

This DOES work, but only in 4.3.1:

> // bindmaster = "bindmaster1.<%= @fqdn
> %>" // bindmaster = "bindmaster1.<%=
> @domain %>"

In 4.5.1, you get an error, at least from epp validate:

> [root@puppet-master5 templates]#
> puppet epp validate
> ./namedresolver.conf Error: Syntax
> error at '@' at
> ./namedresolver.conf:4:33 Error:
> Errors while validating epp

In conclusion it seems inadvisable to use epp templates since the syntax varies wildly between puppet versions.

What did work was switching to the "get variable from hiera in manifest, use in template" pattern. E.g. in manifests/namedresolver.pp:

$b = hiera('namedresolver::bindmasters')

and in templates/namedresolver.erb:

// HIERA: namedresolver::bindmasters = "<%= @b %>"

edit flag offensive delete link more
0

answered 2017-05-02 07:43:20 -0500

DarylW gravatar image

updated 2017-05-02 07:43:54 -0500

in an EPP template, don't you need to explicitly use the $facts[] hash?, i.e. $facts['fqdn']

https://docs.puppet.com/puppet/latest/lang_facts_and_builtin_vars.html#the-factsfactname-hash

edit flag offensive delete link more
0

answered 2017-04-27 06:49:16 -0500

puser gravatar image

updated 2017-04-27 06:49:52 -0500

Try this:

<%= $::fqdn %>

Where fqdn is your fact.

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-04-26 17:31:17 -0500

Seen: 234 times

Last updated: May 02