Ask Your Question
1

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

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

Adam Ryczkowski gravatar image

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

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`
      true
    else
      false
    end   
  end 
end

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
1

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

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: http://docs.puppetlabs.com/guides/custom_facts.html#using-other-facts

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

Comments

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

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 -0500 )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 -0500 )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 -0500 )edit
1
Ancillas gravatar imageAncillas ( 2014-02-04 11:29:20 -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: 2014-02-03 12:50:35 -0500

Seen: 297 times

Last updated: Feb 03 '14