Hi Stefan,
My apologies that I did not get back sooner. What you are suggesting
yields the same results I was seeing before. Let me try to explain
better:
Using no modules (just standard puppet types), I can do this:
---
Package {
notify => Exec["package-changed"]
}
exec { "package-changed":
command => "/bin/true",
refreshonly => true;
}
package { "vim-enhanced":
ensure => installed;
}
---
If the above code happens to install vim-enhanced, then I will see
output like this:
---
Notice: /Stage[main]//Package[vim-enhanced]/ensure: created
Notice: /Stage[main]//Exec[package-changed]: Triggered 'refresh' from 1
events
Notice: Finished catalog run in 4.75 seconds
---
The 'Package {}' defaults are applied and the Exec gets notified.
Now, I write a simple module with a type like this:
---
Puppet::Type.newtype(:foo) do
newparam(:title) do
isnamevar
end
def eval_generate
resources = []
resources << Puppet::Type.type(:package).new(:title => self.title)
resources
end
end
---
All it does is add a new package resource via eval_generate. I execute
it using a manifest that looks like this:
---
Package {
notify => Exec["package-changed"]
}
exec { "package-changed":
command => "/bin/true",
refreshonly => true;
}
foo { "vim-enhanced": }
---
It yields the following:
---
Notice: /Package[vim-enhanced]/ensure: created
Notice: Finished catalog run in 5.10 seconds
---
The Exec from the resource defaults in my current scope is not notified.
If they were, the Exec resource should have run, just like in the first
example.
I am looking for a way to generate resources from a type, and have the
resource defaults from the scope they are defined applied to them.
Any other thoughts or suggestions are most appreciated, as always.
Thanks!
- Ryan
> From: "Stefan Schulte" <[email protected]>
> To: [email protected]
> Sent: Wednesday, May 1, 2013 4:54:38 AM
> Subject: Re: [Puppet Users] Retrieve scoped resource defaults from class
> method in custom type
>
> On Tue, 30 Apr 2013 15:37:11 -0700
> Ryan Uber <[email protected]> wrote:
>
> > [accidently sent this to puppet-dev, re-posting to puppet-users]
> >
> > Hello puppet-users,
> >
> > I am working on a module that provides a custom type. The type when
> > called will create new resources in the catalog using syntax like:
> >
> > Puppet::Type.type(:file).new(:title => 'blah')
> >
> > This works fine and the resources are added as expected. However, I am
> > unable to apply any scoped defaults to the generated resources. So
> > something like:
> >
> > File {
> > mode => 0750
> > }
> >
>
> were do you generate the resources? Puppet already has a method
> "eval_generate" that every type can implement and which has to return
> an array of generated resources (that's how puppet generates implicit
> file resource when you use `recurse`). These resources are
> automatically added to the catalog.
>
> So e.g.
>
> Puppet::Type.newtype(:foo) do
> newparam(:name)
> [...]
> def eval_generate
> resources = []
> resources << Puppet::Type.type(:file).new(:title => 'blah')
> resources
> end
> end
>
> I played with it a little bit (wanted to make a proof of concept for
> a `dirtree` type that simulates the behaviour of `mkdir -p`) but I hit
> problems because autorequirements of generated resources do not seem to
> work (e.g. You have File['/foo'] in your puppet manifest and your
> custom type generates a resource File['/foo/bar'] there a no automatic
> dependencies so File['/foo/bar'] may be applied before File['/foo'] but
> maybe I am wrong about that one.
>
> -Stefan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/puppet-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.