Ask Your Question

Is it possible (and how?) to reference a variable from within a custom fact?

asked 2014-02-03 12:50:35 -0600

Adam Ryczkowski gravatar image

updated 2014-02-03 12:52:06 -0600

I need to write a simple custom fact that tests whether a document container can be opened with the LUKS key available to the system or not. The location for the key is system-dependent, and is managed by the puppet itself.

I need to write something like this:

Facter.add(:docexists) do   setcode do
    if `cryptsetup luksOpen --key-file $MyDocsCryptKeyFile $MyDocsCryptFile $MyDocsCryptMapperName`

Unfortunately I know almost nothing of Ruby. Can anyone point me, how to reference the variables (not environment variables) from within Puppet's cutstom fact?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-02-03 13:45:51 -0600

doc75 gravatar image

My guess is that you will have to duplicate some code. You can use facts inside fact, and therefore you can access any fact and redo the code you have in puppet.

You can check how it works here:

If you need more detailed answer, it would be easier to see how you determine the value of the variable mentioned in your question.

Hope this helps.

edit flag offensive delete link more


It is a simple variable (assigned explicitly in manifest, like $MyDocsCryptFile="/home/${user}/.crypt.bin". It is not a fact. I can always write the contents of this variable to ...(more)

Adam Ryczkowski gravatar imageAdam Ryczkowski ( 2014-02-03 14:12:45 -0600 )edit

The problem is that the Puppet client first generates its facts, then sends those facts to the Master so the node can be classified, and a catalog can be compiled ...(more)

Ancillas gravatar imageAncillas ( 2014-02-03 16:54:01 -0600 )edit

You could store your key path in an external fact, and reference that in your custom fact.

Ancillas gravatar imageAncillas ( 2014-02-03 17:00:21 -0600 )edit

@Ancillas Thank you, I suspected that. Could you tell me, is there any more elegant way to create such variable-storing facts other than by creating a temporary file? Is there ...(more)

Adam Ryczkowski gravatar imageAdam Ryczkowski ( 2014-02-04 01:43:54 -0600 )edit
Ancillas gravatar imageAncillas ( 2014-02-04 11:29:20 -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

1 follower


Asked: 2014-02-03 12:50:35 -0600

Seen: 312 times

Last updated: Feb 03 '14