Ask Your Question

Get variable from module A into module B

asked 2016-06-09 04:33:33 -0600

tomasl gravatar image

updated 2016-06-09 04:50:12 -0600

Hi, I'm trying to get a variable value from one class into another class (different modules) but run into issues. From what I have read in the docs you are supposed to be able to include a class multiple times without running into "already declared..." ?!

What I'm trying to do:

Module A (class "abc")

abcvar = 'something'

Module B (class "xyz")

  include abc
  notify {"######my var is: ${$abc::abcvar}": }


  node 'my-test-node'   {
        class {'abc':
          abcvar => 'somethingelse',
  include xyz  


Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Class[abc] is already declared; cannot redeclare at /etc/puppetlabs/code/environments/puppettest/manifests/site.pp:51 at /etc/puppetlabs/code/environments/puppettest/manifests/site.pp:51:3 on node my-test-node Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run

Would this be possible in any other way or am I doing it totally wrong? Many thanks for your feedback

Regards Tomas

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-06-09 07:43:55 -0600

The issue is that while you can include foo using the include function as many times as you like, you can't use the resource-like declarations class { 'foo': abcvar => 'something' }. What can you do, however, is use the Automatic Parameter Lookup in conjunction with Hiera.

edit flag offensive delete link more


Thanks Alex! So that would mean I'd have to redo module A to use Hiera in some way? I tried in module B with: $local = lookup({"name" => "abc::abcvar"}) But it did not find any value. Unfortunately I'm not familiar with Hiera

tomasl gravatar imagetomasl ( 2016-06-09 08:38:04 -0600 )edit

According to your example code, your site.pp is making the resource-like declaration of the class. So instead of passing the parameter in there, you'd have ::abc::abcvar: 'something' in one of your Hiera files. Feel free to open another question if you get stuck with Hiera.

Alex Harvey gravatar imageAlex Harvey ( 2016-06-10 02:28:56 -0600 )edit

Ok, many thanks for your input!

tomasl gravatar imagetomasl ( 2016-06-10 02:50:37 -0600 )edit

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


Asked: 2016-06-09 04:33:33 -0600

Seen: 67 times

Last updated: Jun 09 '16