Ask Your Question
0

How to use puppet module version in the manifest?

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

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

Comments

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 -0500 )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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

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

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|
    JSON.parse(
      File.read(
        Pathname.new(__FILE__).dirname
          .join('../../../../metadata.json')))['version']
            .split('.')[0..1].join('.')
  end
end

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

Comments

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

2 followers

Stats

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

Seen: 54 times

Last updated: May 18 '16