Ask Your Question

How do you use custom facts in a template.

asked 2013-03-05 13:01:51 -0600

kdoswald gravatar image

updated 2013-03-05 13:23:22 -0600

domcleal gravatar image

When I try to use one, it is blank. But if use fqdn it works.

I have custom facts that get loaded from a file /etc/facts.txt In my puppet module they work. In my templates they are not working.

# This is a test <%= @target %> (this does not)  But does work in module.  
# this is test part 2 <%= @fqdn %>  (this works)
edit retag flag offensive close merge delete


If you put notify { $::target: } into test.pp and run "puppet apply test.pp" what output do you get? And does the fact show up if you do 'sudo facter ...(more)

llowder gravatar imagellowder ( 2013-03-05 13:32:14 -0600 )edit

Yes the fact shows up if i do facter -p target.
case $::target { /a/: { $target = "a" } default: { $target = 'wrong' } }

It works fine.

kdoswald gravatar imagekdoswald ( 2013-03-05 13:42:35 -0600 )edit

Sorry I was wrong, facter -p target does not resolve. I was trying it via facter -p |grep target and that works.

kdoswald gravatar imagekdoswald ( 2013-03-05 13:50:00 -0600 )edit

Could you edit your post to include your puppet class, and your custom fact?

Ancillas gravatar imageAncillas ( 2013-03-05 16:37:24 -0600 )edit

Are you using facts.d to load from that facts.txt file?

+1 to Anvillas's comment, though I suggest putting all of this up on (or ...(more)

ryanycoleman gravatar imageryanycoleman ( 2013-03-05 22:48:20 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2013-03-06 12:12:31 -0600

kdoswald gravatar image

I looked into this more, having all my facts dumped to a yaml file. I noticed "target ": " a" With " around target and space.
If I do facter -p target does not work. If I do facter -p "target " does work so changed my template to reference <%= "target " %> and that works now.

edit flag offensive delete link more

answered 2013-03-05 16:36:43 -0600

Ancillas gravatar image

Do you need to assign it to a local variable in your puppet class?

$target = $::target
edit flag offensive delete link more


You shouldn't need to, no.

ryanycoleman gravatar imageryanycoleman ( 2013-03-05 22:48:40 -0600 )edit

Your Answer

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

Add Answer

Question Tools


Asked: 2013-03-05 13:01:51 -0600

Seen: 6,774 times

Last updated: Mar 06 '13