I'd like to call function File.basename
which is available in Ruby. Is it possible in puppet?
Something like:
$filename = basename($download_url)
I'd like to call function File.basename
which is available in Ruby. Is it possible in puppet?
Something like:
$filename = basename($download_url)
Ruby functions are not directly available in Puppet, but you can use inline_template:
$filename = inline_template('<%= File.basename(download_url) %>')
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'
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.