Ask Your Question
0

How do you use custom facts in a template.

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

kdoswald gravatar image

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

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

Comments

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 -0500 )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 -0500 )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 -0500 )edit
1

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

Ancillas gravatar imageAncillas ( 2013-03-05 16:37:24 -0500 )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 gist.github.com (or ...(more)

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

2 Answers

Sort by ยป oldest newest most voted
0

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

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
0

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

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

Comments

You shouldn't need to, no.

ryanycoleman gravatar imageryanycoleman ( 2013-03-05 22:48:40 -0500 )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

Stats

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

Seen: 5,733 times

Last updated: Mar 06 '13