Skip to content

Instantly share code, notes, and snippets.

@cardil cardil/modules.rb
Created Feb 21, 2018

Embed
What would you like to do?
Example custom fact for Facter 3+ with 2 implementations
Facter.add(:modules) do
setcode { simple }
def simple
codedir = Facter::Core::Execution.exec('puppet config print codedir')
list = Facter::Core::Execution.exec("ls #{codedir}/modules").split("\n")
{
count: list.size,
list: list.freeze
}
end
def power
require 'yaml'
require 'puppet'
yaml = Facter::Core::Execution.exec('puppet module list --render-as yaml')
data = YAML.load(yaml)
modules = []
data[:'modules_by_path'].each do |k, list|
list.each do |m|
splited = m.forge_name.split('/')
modules.push({
name: m.forge_name,
company: splited[0],
short: splited[1],
version: m.version
})
end
end
{
list: modules,
names: {
full: modules.map { |m| m[:name] },
short: modules.map { |m| m[:short] }
},
count: modules.size
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.