loki77
2012-Jul-13 22:38 UTC
[Puppet Users] Anyway to get the $name or $title of the resource being called?
Hi - is there way to get the name of the resource being called when its inside a class? For example, if I have something defined as ''my_file'' and I call it like this inside of a class: my_file { "/etc/bashrc": ; } Is there anyway to get the "/etc/bashrc" part in the definition logic itself? It used to work (in like the .24 days maybe?) that I could use $name, but I''m noticing in 2.7 that $name and $title now seem to point to the class that the definition is called in, which breaks my definition. Thanks for your help! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Nick Fagerlund
2012-Jul-13 23:22 UTC
[Puppet Users] Re: Anyway to get the $name or $title of the resource being called?
You may be doing something weird, because $name and $title inside a defined type definition should definitely still refer to the instance''s title. In fact, I just tested it to be sure: define my_file ($message) { notify {$title: message => "$message, and the title is still $title", } } class my_class { my_file {''the title of the resource, not the class'': message => "This is the message", } } include my_class ...should get you: notice: This is the message, and the title is still the title of the resource, not the class notice: /Stage[main]/My_class/My_file[the title of the resource, not the class]/Notify[the title of the resource, not the class]/message: defined ''message'' as ''This is the message, and the title is still the title of the resource, not the class'' notice: Finished catalog run in 0.05 seconds Show us what you''re doing, maybe? -- 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/-/FHhRkovv9fIJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Erik Dalén
2012-Jul-14 08:09 UTC
Re: [Puppet Users] Re: Anyway to get the $name or $title of the resource being called?
On 14 July 2012 01:22, Nick Fagerlund <nick.fagerlund@puppetlabs.com> wrote:> You may be doing something weird, because $name and $title inside a defined > type definition should definitely still refer to the instance''s title. In > fact, I just tested it to be sure: > > define my_file ($message) { > notify {$title: > message => "$message, and the title is still $title", > } > } > > class my_class { > my_file {''the title of the resource, not the class'': > message => "This is the message", > } > } > > include my_class > > ...should get you: > > notice: This is the message, and the title is still the title of the > resource, not the class > notice: /Stage[main]/My_class/My_file[the title of the resource, not the > class]/Notify[the title of the resource, not the class]/message: defined > ''message'' as ''This is the message, and the title is still the title of the > resource, not the class'' > notice: Finished catalog run in 0.05 seconds > > Show us what you''re doing, maybe? >I think the original poster referred to being able to access the title of a resource inside a resource definition (not a defined type). For example: class example { file { ''/tmp/testfile'': content => "foo ${name} bar\n", } Here $name would refer to "example", but he wants to access the name ''/tmp/testfile''. But as the resource definition doesn''t create a new scope there''s no new variables in it. -- Erik Dalén -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
loki77
2012-Jul-14 21:04 UTC
[Puppet Users] Re: Anyway to get the $name or $title of the resource being called?
Thanks Nick - it turned out that it was an issue on my end which was exacerbated by a misunderstanding of the log message and then misreading some online posts. Everything is working fine now. Thanks! On Jul 13, 4:22 pm, Nick Fagerlund <nick.fagerl...@puppetlabs.com> wrote:> You may be doing something weird, because $name and $title inside a defined > type definition should definitely still refer to the instance''s title. In > fact, I just tested it to be sure: > > define my_file ($message) { > notify {$title: > message => "$message, and the title is still $title", > } > > } > > class my_class { > my_file {''the title of the resource, not the class'': > message => "This is the message", > } > > } > > include my_class > > ...should get you: > > notice: This is the message, and the title is still the title of the > resource, not the class > notice: /Stage[main]/My_class/My_file[the title of the resource, not the > class]/Notify[the title of the resource, not the class]/message: defined > ''message'' as ''This is the message, and the title is still the title of the > resource, not the class'' > notice: Finished catalog run in 0.05 seconds > > Show us what you''re doing, maybe?-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
loki77
2012-Jul-14 21:06 UTC
[Puppet Users] Re: Anyway to get the $name or $title of the resource being called?
Nick actually was right - but I then ran into exactly what you''re saying Erik :) I fixed it by using a defined resource in place of the plain file statement, basically how Nick was saying, and it worked great. Thanks for your help guys! On Jul 14, 1:09 am, Erik Dalén <erik.gustav.da...@gmail.com> wrote:> On 14 July 2012 01:22, Nick Fagerlund <nick.fagerl...@puppetlabs.com> wrote: > > > > > > > > > > > You may be doing something weird, because $name and $title inside a defined > > type definition should definitely still refer to the instance''s title. In > > fact, I just tested it to be sure: > > > define my_file ($message) { > > notify {$title: > > message => "$message, and the title is still $title", > > } > > } > > > class my_class { > > my_file {''the title of the resource, not the class'': > > message => "This is the message", > > } > > } > > > include my_class > > > ...should get you: > > > notice: This is the message, and the title is still the title of the > > resource, not the class > > notice: /Stage[main]/My_class/My_file[the title of the resource, not the > > class]/Notify[the title of the resource, not the class]/message: defined > > ''message'' as ''This is the message, and the title is still the title of the > > resource, not the class'' > > notice: Finished catalog run in 0.05 seconds > > > Show us what you''re doing, maybe? > > I think the original poster referred to being able to access the title > of a resource inside a resource definition (not a defined type). For > example: > > class example { > file { ''/tmp/testfile'': content => "foo ${name} bar\n", > > } > > Here $name would refer to "example", but he wants to access the name > ''/tmp/testfile''. But as the resource definition doesn''t create a new > scope there''s no new variables in it. > > -- > Erik Dalén-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.