0

I want to make some dynamic configurations details in the puppet master side before it makes a deployment on puppet agent. So I want to send significant amount of configuration details along with the request of the agent to master. Is there a proper way to do this in puppet ?

Regards, Malintha Adiakri

Malintha
  • 4,512
  • 9
  • 48
  • 82

2 Answers2

2

Yes! There is facter. This is how I use it and what I find most robust but there are other ways to define new facts.

For example if you want to add role of the server then you can do export FACTER_ROLE=jenkins

Now you can see that command facter role will print jenkins. Yay! After running puppet agent all facts known to system will be passed to thenpuppetmaster. Be aware that service puppet will not know fact that you just defined because it runs in other scope.

I put my facts in file .facts and source it before apply.
This is my script that runs from cron:

#!/bin/bash source /root/.facts puppet agent -t --server puppetmaster.example.com --pluginsync

3h4x
  • 936
  • 8
  • 14
  • Thank you for the answer. Now I run the command "sudo puppet agent --test" to triger the agent node. According to my understanding if we want to send the "FACTOR_ROLE" attribute to the puppet agent we can do it by executing "sudo puppet agent --test export FACTER_ROLE=jenkins" command in the agent side. Am I correct in this case ? – Malintha Jun 16 '14 at 09:53
  • "pluginsync" does sending facters to the master here ? – Malintha Jun 16 '14 at 10:07
  • 1
    No, it doesn't. The magic here is source .facts file which will have export like `export FACTER_ROLE=jenkins` – 3h4x Jun 16 '14 at 10:19
  • Then How can we get the sent attributes from puppet master end? for ex: for the FACTOR_ROLE case what is the command should be executed in puppet master side ? – Malintha Jun 16 '14 at 10:27
  • @Malintha for this direction you need custom facts, for which "pluginsync" does indeed play a part. If only someone would elaborate on this concept in a full fludged answer *hint,hint* ;-) – Felix Frank Jun 16 '14 at 10:29
  • It is in puppetmaster catalog. To easily look through the data install PuppetDB and in manifest you can use it as variable $::role – 3h4x Jun 16 '14 at 11:36
2

While the previous answer is correct, I'm opening this as a new one because it's significant. Defining FACTER_factname variables in the agent's environment is a nice and quick way to override some facts. If you wish to rely on your own facts for production purposes, you should look to custom facts instead.

In its basic form, you use it by deploying Ruby code snippets to your boxen. For an easier approach, take special note of external facts. Those are probably the best solution for your problem.

Also note that as of Facter 2 you can contain complex data structures in your facts and don't have to serialize everything into strings. If the amount of data from the agent is high, as you emphasize, that may be helpful.

Felix Frank
  • 8,125
  • 1
  • 23
  • 30