Question

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.

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top