Ask Your Question

facter syntax help

asked 2017-08-29 13:19:18 -0500

I need to do something like this:

require 'base64'

Facter.add(:app_vault_token) do

  confine :kernel => 'Linux'
  setcode do
    Facter::Core::Execution.exec("curl --header \"X-Vault-Token: ${vault_root_token}\" --request POST --data @payload_${app_name}.json 
       http://active.vault.service.consul:8200/v1/auth/token/create -o \"/opt/tech_admin/token_created_for_app.json\" | jq -r \'.auth.client_token\'")


Is it allowed to have $variables inside the custom fact code?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-08-30 07:46:34 -0500

DarylW gravatar image

If you haven't already, check out the documentation

Facter is a totally separate run from catalog compilation, so it has no concept of variables, unless explicitly provided to the fact. You would typically need to access 'variable' information either from the system itself, or referencing other facter facts. To see what is available in your environment, you could call the env command inside of your exec statement.

If you wish to reference information from other facts, you can use Facter.value(:other_fact), as noted here.

It may be helpful to understand a rough timeline of events. I answered a similar question here, which I'll copy to this post

The rough flow of what happens is as follows

  • The master sends any 'plugins' to the client via pluginsync, which covers custom types, custom facter facts, etc.
  • The client then runs facter, gathers the facts and sends them back to the master.
  • The master then uses information gathered from the facts, and any information it needs from puppetdb (exported resources, etc) to compile the resource catalog. This is the list of things that puppet should be managing on your system, and the state they should be in.
  • The client receives the catalog from the master, and gathers up the state on the current system based on what resources the catalog requires (you can see this by running puppet resource service to see the information puppet knows about the services on your system, or puppet resource file /etc/hosts to see information about a specific resource that isn't gathered in bulk)
  • The client then uses the custom and built in resources to change 'what it is' to 'what it should be'.
  • Any successes and errors are gathered up from the run into the report.yaml, and shipped to (the master / puppetdb)
edit flag offensive delete link more

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: 2017-08-29 13:19:18 -0500

Seen: 204 times

Last updated: Aug 30