${name} returns class name instead of resource namevar

26 views
Skip to first unread message

Francis Pereira

unread,
May 20, 2014, 6:36:40 AM5/20/14
to puppet...@googlegroups.com
When using a custom resource to deploy java $name is not the name of the resource but the name of the class in the below mentioned example

 java::setup { "${myapplication::params::app_username}-jdk_7u51":
.......
    cachedir      => "/var/lib/puppet/file_cache/${name}-working",

  }

Shouldn't $name = ${myapplication::params::app_username}-jdk_7u51 ?


Francis Pereira

José Luis Ledesma

unread,
May 20, 2014, 7:51:32 AM5/20/14
to puppet...@googlegroups.com

No, it is the current $name, not the resource one.

Regards,

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CABCZsNFgJ6GbK0UAmVdxhONb9D1rde1pnFXz-tjZmBj1BBMg9w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

jcbollinger

unread,
May 20, 2014, 9:51:07 AM5/20/14
to puppet...@googlegroups.com


No.  The situation is analogous to a function call: if the argument list contains a variable, the value passed is the value of the variable in the calling scope, not the value of any same-named local variable in the called function.


John

Johan De Wit

unread,
May 20, 2014, 4:14:36 PM5/20/14
to puppet...@googlegroups.com
Hi,

I think you are mixing the 'define' a  resource  and 'use' resource type.

$name is an automatic variable that is set by puppet, and will be in the case of a defined resource, the resource title you give it when 'using' that defined resource

You can use the $name in the define <your type> { } , and in that scope it will be given your example :  ${myapplication::params::app_username}-jdk_7u51.

Outside the definition of your resource (the file beginning with define <whatever> {} ) the $name var contains the $name of the class you are using your defined resource .

I hope i did not confuse you more now.

but read http://docs.puppetlabs.com/puppet/latest/reference/lang_defined_types.html#title-and-name

especially the part about uniqueness. 

An to make it much more difficult, one should start using $title in defined resources instead of $name.

the why is explained in the same link I gave.

I hope it helps.

Grts
Jo

For more options, visit https://groups.google.com/d/optout.


-- 
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer              (805008667232363)
Puppet Certified Professional 2013/2014 (PCP0000006)
_________________________________________________________
 
Open-Future                 Phone     +32 (0)2/255 70 70
Zavelstraat 72              Fax       +32 (0)2/255 70 71
3071 KORTENBERG             Mobile    +32 (0)474/42 40 73
BELGIUM                     http://www.open-future.be
_________________________________________________________
 

Upcoming Events:

Linux Training | https://www.open-future.be/linux-training-5-till-9th-may

Puppet Introduction Course | https://www.open-future.be/puppet-introduction-course-12th-may

Puppet Fundamentals Training | https://www.open-future.be/puppet-fundamentals-training-13-till-15th-may

Zabbix Certified Specialist | https://www.open-future.be/zabbix-certified-specialist-training-19-till-21th-may

Zabbix Certified Professional | https://www.open-future.be/zabbix-certified-professional-training-22-till-23rd-may

Subscribe to our newsletter: http://eepurl.com/BUG8H


Reply all
Reply to author
Forward
0 new messages