Puppet Type Munge help...

213 views
Skip to first unread message

Gavin Williams

unread,
Nov 12, 2012, 8:16:20 AM11/12/12
to puppet...@googlegroups.com
Afternoon all...

I'm trying to use Munge in a custom Puppet type to set the param value to that of another param if the current value is null...

Code I've got is:

Puppet::Type.newtype(:netapp_export) do
  @doc = "Manage Netapp NFS Export creation, modification and deletion."

  apply_to_device

  ensurable do
    desc "Netapp NFS Export resource state. Valid values are: present, absent."

    defaultto(:present)

    newvalue(:present) do
      provider.create
    end

    newvalue(:absent) do
      provider.destroy
    end
  end

  newparam(:name) do
    desc "The export name."
    isnamevar
  end

  newparam(:persistent) do
    desc "Persistent export?"
    newvalues(:true, :false)
    defaultto(:true)
  end

  newparam(:path) do
    desc "The filer path to export."
    Puppet.debug("Validating path param.")
    munge do |value|
      if value.nil?
        Puppet.debug("path param is nil. Setting to #{@resource[:name]}")
        resource[:name]
      else
        Puppet.debug("path param is not nil.")
      end
    end
    #Puppet.debug("path value is: #{@resource[:path]}.")
  end

end


However I'm not having any success with the above.

Any ideas???

Cheers
Gavin

Brice Figureau

unread,
Nov 12, 2012, 9:47:45 AM11/12/12
to puppet...@googlegroups.com
Hi,

I think you should direct those e-mails to the puppet-dev mailing list,
you'll get certainly more answers there.

Also, I didn't closely read your previous posts about the NetApp
provider you're writing, but let just me say that's awesome!
Well, what kind of error or output do you get?

> Any ideas???

Isn't it better to use a defaultto, like this:

defaultto { @resource[:name] }

(That's what I did in the network device interface type, and it was
working)
--
Brice Figureau
Follow the latest Puppet Community evolutions on www.planetpuppet.org!

Gavin Williams

unread,
Nov 12, 2012, 10:11:22 AM11/12/12
to puppet...@googlegroups.com, brice-...@daysofwonder.com
Scott

Cheers for your response, and the tip on defaultto... That's solved the issue perfectly :) :D

Cheers
Gavin
Reply all
Reply to author
Forward
0 new messages