On Thursday, November 6, 2014 8:30:16 PM UTC-6, w...@stanford.edu wrote: > > In puppet 2.7 we use the following construct. > > define some::fun( > ensure => present, > sname => 'some.server.com' >
This isn't the source of your problem, but do be aware that setting default parameter values via '=>' is deprecated. You should use '=' instead (which works in Puppet 2.7, too). > ) { > include some::fun_setup > # Template uses sname > file {"/path/$name": > content => template("${name}.erb"), > } > } > > class some::fun_setup { > file{"/etc/ssl/certs/${sname}": > source => "puppet:///modules/some-files/${sname}.ca.pem" > } > } > > The reference to sname in some::fun_setup does not work in puppet 3. > No, it wouldn't. You are relying on dynamic scoping, which was dropped in Puppet 3. > Not surprising given the scoping changes. The problem is I am not sure > how to reference sname defined in the resource from the class > some::fun_setup. > You cannot safely do this, and it is anyway not sensible. Indeed, it might not do quite what you think it does even in Puppet 2. Consider that if you make some::fun a defined type instead of a class, then you are explicitly providing for the possibility that multiple instances may be declared. Consider also that if you make $sname a parameter of type some::fun, then you are providing for it to have different values for different instances. So what do you suppose will happen in Puppet 2.7 if you do this: some::fun { 'f1': sname => 'server1.my.com' } some::fun { 'f2': sname => 'server2.my.com' } ? Hint: classes are singletons; you get at most one instance of any given class, no matter how many times a declaration of that class is evaluated. > In reading the documentation I think something like $some::fun::sname > should work, but it doesn't. > That form works if some::fun is a class, but you cannot access resource parameters that way (defined type *instances* are resources). > What is the correct way to reference sname from some::fun_setup? > > The goal is to be able to have manifests that use some::fun as follows: > > some::fun{'fragment1': ensure => present} > some::fun{'fragment2': ensure => present} > ... > Your design is flawed. You need to rethink it. Some of your options are - make some::fun_setup a defined type, and pass $sname as a parameter (this will break if you have multiple some::fun instances with the same $sname) - externalize $sname, remove it from some::fun's parameter list, and have class some::fun_setup load it via Hiera (this does not support different some::fun instances relying on different $sname, but that's not actually working for you now) If you need to support multiple some::fun_instances, with some but not all sharing any given $sname (i.e. a many to many relationship), then you're going to need to make deeper changes. John -- 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 puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/b413f1f7-e501-4a4d-8ee3-ba608f1e4f6a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.