0
votes

I would like to retrieve a module's version through Puppet.

For example:

notify { "module version is $module_version": }

but this is not possible with Puppet. That's why I would like to add a custom resource or function using Ruby which can handle that.

My idea is to use Ruby to open the metadata.json, get the module's version, and add it to the facts. Do you think it's possible to open the metadata.json of the module in question? Do you have any other ideas?

1

1 Answers

2
votes

You can use the load_module_metadata function from stdlib to accomplish this: https://github.com/puppetlabs/puppetlabs-stdlib#load_module_metadata

For example, to achieve what you are looking for in your example snippet above, you would do:

$metadata = load_module_metadata('module_name')
notify { "module version is ${metadata['version']}": }

Note that the return value of load_module_metadata will be a hash with strings for keys and values, so use the corresponding hash lookup structure in Puppet accordingly ($hash_name['hash_key'] returns the corresponding string value for the key).