Ask Your Question

How to use puppet module version in the manifest?

asked 2016-05-17 20:56:14 -0600

penedo gravatar image

We configure repositories (Yum and Apt) with package versions based on the version of the Puppet module. e.g. if the manifest (through Puppetfile) has Puppet module version 3.2 then we want the repo URL to contain the string "3.2" somewhere.

Right now, we have a fact which extracts the module version from the output of "puppet module list", but this works only when the module is installed locally (e.g. in Vagrant, or when running stand-alone agent), but not when using Puppet Master.

Is there a way to include the module version in the manifest automatically, without having to maintain the variable "manually"?

edit retag flag offensive close merge delete


Worst case, could you have a function or something that would be able to access the metadata.json from a relative path? You would be able to parse it for output...

DarylW gravatar imageDarylW ( 2016-05-17 22:36:35 -0600 )edit

Ah right, forgot about server-side functions. There is still the tricky part of actually finding the module installation location from inside the functions...

penedo gravatar imagepenedo ( 2016-05-18 06:04:12 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-05-18 21:22:36 -0600

penedo gravatar image

Thanks very much to @DarylW for the pointer to functions. Here is how I implemented it:

module Puppet::Parser::Functions
  newfunction(:module_version, :type => :rvalue) do |args|

It extracts the first two components of the version string, which is what I need for my particular needs.

This code should go in lib/puppet/parser/functions/module_version.rb under the module's top directory.

edit flag offensive delete link more


Glad I could Help! I was just poking around in the lib directory the other day while trying to abstract the ruby code out of my facter facts, so that's what had me think of using the relative path!

DarylW gravatar imageDarylW ( 2016-05-19 20:53:16 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2016-05-17 20:56:14 -0600

Seen: 212 times

Last updated: May 18 '16