1

I wrote a module for chruby, the Ruby version manager. This works fine with Puppet v3, but I just started using Puppet v4 and the $version param does not get interpolated in the $source_url string.

class chruby(
  $version,
  $source_url = "https://github.com/postmodern/chruby/archive/v${version}.tar.gz",
) {

I'll always want a version passed, and I may want a source url passed though usually not - have the rules changed that this is no longer allowed, and how can I get this to work with v4? I tried this:

  unless $source_url {
    $source_url = "https://github.com/postmodern/chruby/archive/v${version}.tar.gz"
  }

In the class body but it also doesn't interpolate. I've checked there is a $version using notice. I can't find how to do this from the docs:

I have started using Hiera for some things and understand this may remove the need for defaults, but I've just started using it this last week so I'm not clear on that yet, but still would like to understand why this has changed from v3 to v4.

2
  • It has never worked reliably in Puppet to reference the value of one class or defined-type parameter in the default value of another, where "reliably" means being able to predict whether it will work before trying it the first time for a given version of a given class. Don't do that. If it seemed to work for you before then you were just lucky. With only two class parameters, you had a 50% chance of that. If it stopped working when you upgraded, then your luck failed. Mar 7, 2016 at 23:37
  • To be fair to me, it worked reliably for me over a couple of years with multiple parameters using Puppet 3, and I got it from someone else (I don't remember where though) so I'll blame them. To be fair to Puppetlabs, they rewrote the parser to be stricter and said it was a breaking change so I won't moan about it. Much :)
    – ian
    Mar 8, 2016 at 13:34

1 Answer 1

2

Use another variable:

class chruby(
  $version,
  $source_url = undef,
) {
  $actual_source_url = $source_url ? {
    undef   => "https://github.com/postmodern/chruby/archive/v${version}.tar.gz",
    default => $source_url,
  }
  notice($actual_source_url)
}
1
  • Thank you, very helpful.
    – ian
    Mar 8, 2016 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.