0

Is there a possibility of deploying custom facts based on the hostname/ipaddress of the machine. Suppose i have 2 custom fact files,

machine1.rb #contains facts specific to machine1

machine2.rb #contains facts specific to machine2

Now my requirement is that depending on the hostname or the ip address, the corresponding custom facts file should be copied to the corresponding machine. I tried googling but didnt help. Please let me know.

Iowa
  • 2,171
  • 4
  • 22
  • 31
  • 2
    You are trying to mix custom facts and external facts. This will be much easier if you choose one or the other. Is the hostname/ipaddress matching done with a regexp and associated with multiple machines, or is it hardcoded and associated with one machine? – Matthew Schuchard Sep 20 '16 at 14:02
  • @Matt, Thanks Matt. Honestly i was not aware of external facts and i was trying only with custom facts. The external facts might be the way for me if i am right. And, regarding the matching, i am doing it against multiple machines and it is hardcoded. The thing is i have several facts which have to be set in a machine based on the hostname/ipaddress, and i thought maybe there is a way to keep facts per machine in a separate file, say machine1.erb. So does external facts work out in my case? – Iowa Sep 20 '16 at 14:10
  • 1
    So if you use external facts, then you can set key value pairs that are associated with each machine type (like a hash for each) and then have the Puppet code access each accordingly. You can also use scripts with the external facts that populate the facts based on the hostname/ipaddress (which would be checked inside the script). If you use custom facts, then you can set conditionals in your ruby code based on the hostname/ipaddress, but that would be more dynamic facts than static. I can show you how to do any of this if you want. – Matthew Schuchard Sep 20 '16 at 14:23
  • @Matt - Thanks a lot Matt. Can you please show how it can be done. Actually what i wanted was have env specific facts file. And dynamically fetching the information can be tricky in this case as there are multiple instances running and duplicate folders present which cant be removed. So have decided to go with the static approach. And another quick question, is there a GUI for facter? – Iowa Sep 21 '16 at 07:05
  • There is no GUI for Facter. Are you using Facter 2 or 3? – Matthew Schuchard Sep 21 '16 at 11:37
  • I am currently using facter 2. – Iowa Sep 22 '16 at 08:58
  • I have double checked and Facter 2 does not support external fact hashes, but only key value pairs. That makes this tricky. However, when you say 'env specific facts file', do you mean per directory environment? That would make this easy again. – Matthew Schuchard Sep 22 '16 at 13:35
  • Thanks a lot Matt :). The way i have done it as of now is create external facts with naming convention as "${hostname}_facts.sh" and puppet master copies the appropriate one to the target env. Would have been easier if there was a GUI for facter for editing facts as and when required since there are certain facts that cant be determined dynamically. – Iowa Sep 23 '16 at 06:22

0 Answers0