5

I'd like to call function File.basename which is available in Ruby. Is it possible in puppet?

Something like:

$filename = basename($download_url)
Tombart
  • 2,013
  • 3
  • 27
  • 47

3 Answers3

11

Ruby functions are not directly available in Puppet, but you can use inline_template:

$filename = inline_template('<%= File.basename(download_url) %>')
Gergo Erdosi
  • 226
  • 2
  • 3
1

meanwhile it is possible to use the puppetlabs-stdlib which provides a basename() function.

Returns the basename of a path (optionally stripping an extension).

basename('/path/to/a/file.ext') returns 'file.ext'
basename('relative/path/file.ext') returns 'file.ext'
basename('/path/to/a/file.ext', '.ext') returns 'file'
c33s
  • 1,465
  • 3
  • 20
  • 39
0

No, you can not call arbitrary Ruby functions in a Puppet manifest, but you can do so in Puppet templates which use ERB. Have a look at the inline_template function, which might be useful for your use case.

daff
  • 4,729
  • 2
  • 26
  • 27