Difference between revisions of "Facterhandson"
From Gridkaschool
Line 8: | Line 8: | ||
# Write a custom fact or code external fact to produce "role" fact |
# Write a custom fact or code external fact to produce "role" fact |
||
## One way of doing the custom fact, which should live in $modulepath/lib/facter/role.rb: |
## One way of doing the custom fact, which should live in $modulepath/lib/facter/role.rb: |
||
− | <center> |
||
<source lang="ruby"> |
<source lang="ruby"> |
||
require 'facter' |
require 'facter' |
||
Line 17: | Line 16: | ||
end |
end |
||
</source> |
</source> |
||
− | </center> |
||
Using the facts |
Using the facts |
||
Line 23: | Line 21: | ||
# Use the facts as variables to populate motd |
# Use the facts as variables to populate motd |
||
# Remember that facts are top-scope, so you will want $::role and $::owner |
# Remember that facts are top-scope, so you will want $::role and $::owner |
||
− | #*<source lang="ruby">require 'facter'<br />Facter.add("role") do<br />setcode do<br />%x{cat /etc/role}.chomp<br />end<br />end</source> |
||
− | </center> |
Revision as of 10:22, 4 September 2014
Note: mediawiki is ugly, sorry
- Create an external fact with key "owner" with value of your name, or your team
- tips:
- you want to create /etc/facter/facts.d/owner
- use a puppet file resource, or try using $modulepath/facts.d/owner
- Add a file "/etc/role" with choice of value of "web", "data", or "compute"
- use a puppet file resource to create the file
- Write a custom fact or code external fact to produce "role" fact
- One way of doing the custom fact, which should live in $modulepath/lib/facter/role.rb:
require 'facter'
Facter.add("role") do
setcode do
%x{cat /etc/role}.chomp
end
end
Using the facts
- facter -p
- Use the facts as variables to populate motd
- Remember that facts are top-scope, so you will want $::role and $::owner