Creating resources from ruby?

asked 2018-09-12 09:14:31 -0500

jmr gravatar image

Hi,

I'm trying to implement a defined type for aufs (layered file system) in ruby. The type is supposed create the directories making up the file system and the mount point, add the fstab entry and mount it. Creating the directories works fine, but I cannot figure out how to create the mount resource from ruby. Looking at the ensure_resource function from stdlib, I tried adding (using file instead of mount as mount will not work as a regular user):

require 'puppet/file_system'
require 'puppet/parser/functions'
Puppet::Type.type(:aufs).provide(:aufs, :parent => Puppet::Provider) do
  [...]
  def create
    [...]
    Puppet::Parser::Functions.function(:create_resources) 
    #if this line is removed, the run works:
    function_create_resources([File, { "/tmp/test" => 'ensure' => 'directory'}])
  end
end

This fails with

    Error: /Stage[main]/Main/Aufs[/tmp/test/puppet]/ensure: change from 'absent' to 'present' failed: Could not set 'present' on ensure: undefined method `function_create_resources' for Aufs[/tmp/test/puppet](provider=aufs):Puppet::Type::Aufs::ProviderAufs (line: 1)

I don't actually need a mount resource, but I'd like to use the functions implemented there instead of modifying the fstab, making sure everything up to the mount point is mounted etc.

best regards, Jan-Martin

edit retag flag offensive close merge delete