Ask Your Question
1

correct ordering: class depending on custom fact

asked 2013-12-12 13:52:25 -0500

Thynan gravatar image

updated 2013-12-12 14:09:37 -0500

Hi!

I have the following problem: I have a class "classA" which reads some values from hiera. The server who executes "classA" needs to have a custom fact "custom-role", so that "classA" gets the values from the correct hiera file.

So my plan was to add an external fact via puppet, before the class gets executed, like so:

#the external fact which assigns role to server
file{"/etc/facter/facts.d/profile.txt":
    ensure => file,
    content => 'role=some_role',
    mode => '644',
}
#the class which gets data from hiera, but only if the server has the correct role
include classA

#the external ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-12-13 07:11:50 -0500

dgmorales gravatar image

Well, I'm pretty sure (and you may know that already) that facts are only read before catalog compilation, so your code installs the fact, but is not aware of it until the next run.

You could use a ruby fact. Those already get synced before the agent runs. Even if you never touched ruby, it's pretty trivial to write one like you need. There's even an example of a "role" fact in that doc.

edit flag offensive delete link more

Comments

OK, using ruby facts instead of external facts sounds like a nice compromise. Thanks!

Thynan gravatar imageThynan ( 2013-12-15 03:40:01 -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

1 follower

Stats

Asked: 2013-12-12 13:52:25 -0500

Seen: 117 times

Last updated: Dec 13 '13