Facterhandson: Difference between revisions

From Gridkaschool
Jump to navigationJump to search
No edit summary
No edit summary
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Note: mediawiki is ugly, sorry
# Create an external fact with key "owner" with value of your name, or your team
# Create an external fact with key "owner" with value of your name, or your team
## tips:
## tips:
Line 8: Line 7:
# 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>
require 'facter'
<source lang="ruby">
Facter.add("role") do
require 'facter'
Facter.add("role") do
setcode do
setcode do
%x{cat /etc/role}.chomp
%x{cat /etc/role}.chomp
end
end
end
end
</source>
</center>


Using the facts
Using the facts
Line 23: Line 19:
# 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>

Latest revision as of 10:34, 4 September 2014

  1. Create an external fact with key "owner" with value of your name, or your team
    1. tips:
    2. you want to create /etc/facter/facts.d/owner
    3. use a puppet file resource, or try using $modulepath/facts.d/owner
  2. Add a file "/etc/role" with choice of value of "web", "data", or "compute"
    1. use a puppet file resource to create the file
  3. Write a custom fact or code external fact to produce "role" fact
    1. 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

  1. facter -p
  2. Use the facts as variables to populate motd
  3. Remember that facts are top-scope, so you will want $::role and $::owner