On Wednesday, June 27, 2012 12:27:17 AM UTC-5, Yanis Guenane wrote: > > What I actually would like it to create a kind of dependency. > > I would like that a parameter X of any instance of type 'b' *depends* on > the path param of the 'a' resource instance namely passed as a parameter. > > file {'test' : >> ensure => present, >> name => 'test.txt', >> *within* => dir, >> } >> >> file {'dir' : >> ensure => directory, >> name => 'dir', >> path => '/tmp' >> } >> > > This is not the best example since file does not work this way but its the > closest one to what I would like. > > Imagine file was a custom type, so I know in the *within *param I am > expecting a File[] resource insance. I'd like to know if there is any way I > can get the parameters of this resource instance (dir)? (Something like > extrapolating it, or accessing it through catalog) > > In the previous case File['test'] will end up being located at > '/tmp/text.txt', appending dir.path + test.name, without specifying the > path in File['test'] but just the directory it depends on. > > I hope I could explain myself a bit better,
Yes, you did, and that's pretty much what I had supposed you were after. Chances are good that you could force this to work, but I cannot advise you about details, and I recommend you do not follow this path. Nothing else in Puppet works the way you describe. More generally, despite appearances, implementation language, and some of the terminology used in the Puppet community, Puppet DSL is not an object-oriented language in any conventional sense, but that's how you want to make it behave (albeit only within the confines of your custom type). The fact that you are trying to do something so non-idiomatic should give you pause. The usual ways to approach this sort of problem all involve making multiple classes and / or resources pull data from the same source, typically one of global or class variables, defined type parameters, an external data repository, or class parameters. For example, if the two associated resources are going to be declared together, then you could do this: define my_module::file_and_directory($filename, $dir) { file {$dir : ensure => directory, } file {"${dir}/${filename}": ensure => present, } } my_module::file_and_directory { "foo": filename => 'file', dir => '/tmp' } John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/GMMVj0r6oiQJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.