On Thursday, April 24, 2014 7:42:34 AM UTC-5, Felix.Frank wrote:
>
> Rule of thumb with defined types: Resources that those declare will want 
> to have the $title (or $name) or their enclosing defined type in their 
> title to avoid clashes. 
>
> download_tomcat { "tomcat-dl-for-$name": version => $version } 
>
>

Yes, but in this case there would still be a problem with that because the 
defined type manages a File whose path depends only on the tomcat version.  
That could be resolved by giving each tomcat instance its own, separate 
tomcat tarball.  That gets a bit messy, however, not to mention wasteful.

Personally, I'd have the tomcat instances share by declaring the tomcat 
distribution virtually, something like this:

tomcat/manifests/dist.pp:
----
define tomcat::dist() {
  $tc_name = "apache-tomcat-${title}"
  $tarball = "${tc_name}.tar.gz"
  $src_dir = '/usr/local/src'

  file{ "${src_dir}/${tarball}":
        ensure => present,
        owner  => root,
        group  => app,
        mode   => '0755',
        source => "puppet:///modules/tomcat/${tarball}",
  } 

  exec{"extract ${tc_name}":
      command => "/bin/tar xzf ${src_dir}/${tarball}",
      cwd     => ${src_dir},
      creates => "${src_dir}/${tc_name}",
      require => File["${src_dir}/${tarball}"]
  }
}


tomcat/manifests/init.pp:
----
class tomcat {
  # Better if the available versions were drawn from external data:
  $available_versions = ['6.0.39', '7.0.53', '8.0.5']

  # Virtual declaration(s):
  @tomcat::dist { $available_versions: }

  ...
}


tomcat/manifests/instance.pp:
----
# renamed from ensure_tomcats:
define tomcat::instance(
  $tc_path,
  $version
) {
  include 'tomcat'

  $tc_name = $title

  # Realize instead of declaring:
  realize Tomcat::Dist[$version]

  exec{"$tc_name install":
    ...
    require => Tomcat::Dist[$version]
  }

  ...
}


manifests/site_or_some_other.pp:
----
node XY{
  # no need to "include tomcat" here
  tomcat::instance {
    'tomcat1':
      tc_path => "/app/tomcat1/tomcat",
      version => "7.0.53";
    'tomcat2':
      tc_path => "/app/tomcat2/tomcat",
      version => "7.0.53";
  }
}



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/b45a2749-fcbe-42dd-bc5d-1e1453cf8de0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to