On Saturday, September 20, 2014 2:33:34 PM UTC-5, aar...@gmail.com wrote:
>
> Thanks Neil,
>
> I am not sure I understand exactly what you mean, so I will post the code 
> I have done for testing (I am using different paths, but the concept is the 
> same as the original post). 
>
> Here is the class with the define.  It is in a module called 
> copy_directory.
>
> class copy_directory {
> }
>
> define managed_preferences ($source = undef) {
>   file {"/tmp/":
>     source  => "puppet:///modules/${source}/tmp",
>     recurse => true,
>     owner   => "root",
>     group   => "root",
>     mode    => 600,
>   }
> }
>
> Here is the module that calls it.  
>
> include copy_directory
>
> class test_module {
>   managed_preferences { 'title':
>   source => "$module_name",
>   }
> }
>
> I also created a module called test_module2 with the same code.  I know 
> that file {"/tmp/": is causing the problem, but the entire point is 
> different modules copy files into that directory. To me I'm defining it 
> once, and using it twice.  As I defined it in the copy_directory module, 
> and I am using it in the test_module and test_module2.   What am I doing 
> wrong?
>
>

A class may be declared multiple times (though the resource-like syntax, if 
used, must be the first one evaluated), with the same effect as declaring 
it just once.  That is, classes are idempotent.  Ordinary resources, 
including defined-type instance, may be declared only once.  Given that 
defined types are usually meant to allow multiple instances, it follows 
that defined type instances must declare only resources that wholly belong 
to them; they must not not declare shared resources.  Instead, they can 
rely on a class to declare the shared resources.

For example:

class my_module::preferences_base {
  # A shared resource:
  file { '/etc/preferences':
    ensure => 'directory',
    owner  => 'root',
    owner  => 'group',
    mode   => '0644'
  }
}

define my_module::preference_file($source) {
  # relies on the preferences base directory:
  include 'my_module::preferences_base'

  # A file in the preferences base directory:
  file { "/etc/preferences/${title}":
    ensure => 'file',
    source => $source,
    owner  => 'root',
    owner  => 'group',
    mode   => '0644'
  }
}


That should also work if the the shared directory is managed recursively, 
or if the defined type declares a directory instead of a file -- even a 
recursively managed one.  Does that help?


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/8fa2ad9b-3a5a-44ff-a94f-4197314961f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to