voxpupuli / onceover

Your gateway drug to automated infrastructure testing with Puppet
141 stars 45 forks source link

Ruby function in control repo works in Puppet but not found in onceover #315

Open damonmaria opened 2 years ago

damonmaria commented 2 years ago

I have a function lib/puppet/functions/fix_image_tag.rb in my control repo. It works fine in Puppet / production but onceover fails with:

  errors:
    Evaluation Error: Unknown function: 'fix_image_tag'.

Is this expected to work? Or do I need to move it into a module brought in through Puppetfile?

dylanratcliffe commented 2 years ago

That's not expected to work. Puppet only looks for functions (and other ruby stuff) in the lib directory of a module, not at the root of the controlrepo. So you could put it in a module and then have that pulled in though the Puppetfile, or you could could just create a module straight in the controlrepo under the site-modules like in this example module which is located inside a controlrepo: https://github.com/puppetlabs/control-repo/tree/production/site-modules/adhoc

dylanratcliffe commented 2 years ago

Note that the reason site-modules works as a location for modules, is because we told it to look there in the environment.conf e.g. https://github.com/puppetlabs/control-repo/blob/production/environment.conf#L1

damonmaria commented 2 years ago

I can confirm it does work when used in Puppet at that location.

I got the idea from this Puppet documentation which says an upcase function can be placed at /etc/puppetlabs/code/environments/production/lib/puppet/functions/upcase.rb. I have been assuming a control repo maps to an environment. I admit I'm no expert here :)

dylanratcliffe commented 2 years ago

Huh you're right, I had no idea that was possible and I've never seen it used but it does say:

either a module or an environment

Which would mean root of the controlrepo should be fine... So workaround is definitely to put it in a module but I'll re-open this as it does sound like a onceover thing