Ask Your Question
0

2 modules depend on a modules

asked 2014-12-14 02:04:36 -0600

Huy Le gravatar image

updated 2014-12-15 12:36:31 -0600

Hi, I'm having trouble with module dependency. Here's the problem: I have 3 modules: cassandra and zookeeper both depend on java.

# cassandra/manifests/init.pp:
class cassandra {
  class { 'java': }
  package { 'dsc21':
    ensure  => present,
    require => Class['java'],
  }
}

# zookeeper/manifests/init.pp:
class zookeeper {
  class { 'java': }
  package { 'zookeeper':
    ensure  => present,
    require => Class['java'],
  }
}

#site.pp:
include cassandra
include zookeeper

This of course will yell an error since Class['java'] is declared in 2 places. How can I avoid this situation?

Thanks.

EDIT: As suggested by Tomasz Olszewski, include java can be put in place of class { 'java': } if java is a non-parameterized class. Otherwise, please look at my answer.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
3

answered 2014-12-14 07:53:01 -0600

Tomasz Olszewski gravatar image

If java doesn't require any additional parameters, then you can simply change declaration to

include java

Include directive can be repeated multiple times.

edit flag offensive delete link more

Comments

Although 'include java' can be repeated, this doesn't guarantee the evaluation order, that is, Cassandra or Zookeeper may be executed before reaching class Java. However, I have found the solution. Thanks.

Huy Le gravatar imageHuy Le ( 2014-12-14 09:49:53 -0600 )edit
1

You can still call require => Class['java'] when using include.

inhumantsar gravatar imageinhumantsar ( 2014-12-15 12:00:11 -0600 )edit

@inhumantsar: I misunderstood @Tomasz Olszewski. Sorry for that. I've tested and yes, this works too. But not for the case of parameterized class, which is my case.

Huy Le gravatar imageHuy Le ( 2014-12-15 12:31:43 -0600 )edit
0

answered 2014-12-14 09:53:00 -0600

Huy Le gravatar image

updated 2014-12-14 20:21:30 -0600

I have found the solution to my case here. In short:

class tomcat {
  Class['java'] -> Class['cassandra']
}

class zookeeper {
  Class['java'] -> Class['zookeeper']
}

node mynode {
  class { ['java', 'cassandra', 'zookeeper']: }
}
edit flag offensive delete link more
0

answered 2014-12-15 05:56:50 -0600

another way is from the stdlib module you could use the ensure_packages function

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-12-14 02:01:53 -0600

Seen: 203 times

Last updated: Dec 15 '14