The Puppet Labs Issue Tracker has Moved: https://tickets.puppetlabs.com

Feature #1545

The module name should be available as a variable

Added by Felix Schäfer over 5 years ago. Updated almost 4 years ago.

Status:ClosedStart date:09/02/2008
Priority:NormalDue date:
Assignee:Luke Kanies% Done:

0%

Category:newfeature
Target version:2.6.0
Affected Puppet version:0.25.1 Branch:luke/tickets/master/1545-module_name_as_variable
Keywords:

We've Moved!

Ticket tracking is now hosted in JIRA: https://tickets.puppetlabs.com

This issue is currently not available for export. If you are experiencing the issue described below, please file a new ticket in JIRA. Once a new ticket has been created, please add a link to it that points back to this Redmine ticket.


Description

It’s been discussed before in #1104, but I can’t find a ticket for that, so I suppose there isn’t one as of now.

Anyway, it would be nice to know which module some definition is being called from, this would save me some Common_definition { module => module1, } at the beginning of module1.


Related issues

Related to Puppet - Feature #2726: Modules should support package-like metadata Closed 10/15/2009
Related to Puppet - Feature #2729: module metadata version should be accessible to reports Accepted 10/16/2009
Related to Puppet - Bug #4496: module_name variable not consistently set Duplicate 08/07/2010
Related to Puppet - Feature #16874: Caller class name variable Accepted 10/09/2012
Duplicated by Puppet - Feature #3164: Create a $module variable like $name Duplicate 02/08/2010

History

#1 Updated by James Turnbull over 5 years ago

  • Category set to newfeature
  • Status changed from Unreviewed to Accepted
  • Assignee set to Puppet Community
  • Target version set to 4

#2 Updated by Luke Kanies over 5 years ago

  • Subject changed from Name of the calling module to The module name should be available as a variable

#3 Updated by James Turnbull almost 5 years ago

  • Assignee deleted (Puppet Community)

#4 Updated by James Turnbull over 4 years ago

  • Priority changed from Low to Normal
  • Target version changed from 4 to 2.6.0
  • Affected Puppet version changed from 0.24.4 to 0.25.1

#5 Updated by James Turnbull about 4 years ago

  • Target version changed from 2.6.0 to 2.7.x

#6 Updated by Luke Kanies almost 4 years ago

  • Status changed from Accepted to In Topic Branch Pending Review
  • Assignee set to Luke Kanies
  • Target version changed from 2.7.x to 2.6.0
  • Branch set to luke/tickets/master/1545-module_name_as_variable

I’ve added this in my tickets/master/1545-module_name_as_variable branch. The variable name is ‘module_name’:

class mymod {
    notify { "in mymod '$module_name'": }
}

#7 Updated by Alan Barrett almost 4 years ago

What happens if my module calls a define from another module? I think that it would be more useful if $module_name referred to the caller’s module, not the define’s module.

/* /mymodule/manifests/init.pp */
class mymodule {
    util::myfile { "foo": }
}

/* /util/manifests/myfile.pp */
define util::myfile {
    file { "/tmp/$name:
        ensure => file,
        source => "puppet:///${module_name}/${name}",
        # is $module_name "util" or "mymodule"?
    }
}

#8 Updated by Luke Kanies almost 4 years ago

I was afraid you were going to ask that. :/ With my current code, it’s the module that the definition is in, not the caller’s module. The latter is a good bit harder.

Can you provide a use case?

I can kind of see why you want it, but having it a bit more concrete would be useful for me.

#9 Updated by R.I. Pienaar almost 4 years ago

Luke Kanies wrote:

I was afraid you were going to ask that. :/ With my current code, it’s the module that the definition is in, not the caller’s module. The latter is a good bit harder.

Can you provide a use case?

I can kind of see why you want it, but having it a bit more concrete would be useful for me.

the use case Alan shows is what I had in mind too, pre modules we were able to easily create utility file copiers:

define myfile(....) {
   file{$name:
       source => ["puppet:///files/${name}.${fqdn}", "puppet:///files/${name}"]
   }
}

myfile{["/etc/foo", "/etc/bar"]: }

which would take some predefined search order and just fetch it from the single big file server. Now with module we cant do that, we need to somehow know which module to fetch the files from, having modulename to be the caller would make it great. since we can get back to something that simple

#10 Updated by Alan Barrett almost 4 years ago

Like Volcane, my use case is a definition that searches for files, using something like this:

    file { $name:
       source => [
           "puppet:///$module/$basename.$fqdn",
           "puppet:///$module/$basename.$environment",
           "puppet:///$module/$basename.COMMON",
       ],
    }

I currently pass the equivalent of “puppet://$module/$basename” as a parameter to the definition, but if $module could be provided automatically, then I could rewrite the definition to figure out a default $basename from $name, and I could save some effort every time the definition is called.

#11 Updated by R.I. Pienaar almost 4 years ago

Ticket #3951 relates to this, the 3 slash thing will have the same simplification effect.

#12 Updated by Luke Kanies almost 4 years ago

Ok, I’ve added a ‘caller_module_name’ variable in my latest branch which should do what people seem to want – I’d much appreciate people testing to see if this works like you were hoping.

#13 Updated by Nick Lewis almost 4 years ago

  • Status changed from In Topic Branch Pending Review to Closed

Push to master in:

commit:50a626daa1bef956ea63c405fddeaeab8a9a0756

Also available in: Atom PDF