0

I am trying to write a custom facter module that incorporates a fact within a fact for the command via concatenation of the command string plus a facter fact variable:

Facter.add("customfact") do
  setcode do
    $string_to_parse = Facter::Util::Resolution.exec('somecommand' + $::fact)
  end
end

Newbie to ruby and Puppet... 1. What would be the proper syntax to do something with this?

  1. Is there any way to parse the output into an array of facts or what is the correct way to search the $string_to_parse for the content I need.

Here is an example of the output generated with the command:

TAG     security-group  sg-0a7a8a61     aws:cloudformation:stack-name   awseb-e-5tzgj9fq5b-stack

I would need the security group and stack name.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
amanda fouts
  • 347
  • 2
  • 10
  • This is a bit too vague. Goes from how to use another fact in facter (for what reason?) to how do I parse strings in Ruby. Would be much better if you stated exactly what you are trying to accomplish. – rojs Mar 24 '14 at 01:39

1 Answers1

0

You want to use Facter.value(:sourcefact) inside your new fact to access the variable. As for getting the individual values, you probably want those as separate facts, but you could pipe 'somecommand' + Facter.value(:sourcefact) + ' | awk {"print $3"}' will give you the security group (as an example).

Glen Solsberry
  • 11,960
  • 15
  • 69
  • 94