Ask Your Question
0

How to write a wrapper class / Override configuration in pre existing Puppet Class

asked 2016-02-04 07:29:50 -0500

updated 2016-02-05 21:59:14 -0500

I would like to override the values of another class in another Puppet Modules. Please help me by suggesting ways.

Existing Class : ( Module Name : MySQL )

class mysql::server (
  $config_file             = $mysql::params::config_file,
  $includedir              = $mysql::params::includedir)
{
  My Code Logics
}

My Current Class : ( Module Name : Profiles )

class profiles::mysql () {
    class { '::mysql::server':
        config_file => '/opt/arunraj',
        includedir  => true
    }
}

When i am doing like above, I am getting duplicate class declaration error. Which is a best way to override a values between two classes

ERROR:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Class[mysql::server] is already declared; cannot redeclare at /etc/puppetlabs/code/environments/production/modules/profiles/manifests/mysql.pp:2 at /etc/puppetlabs/code/environments/production/modules/profiles/manifests/mysql.pp:2:2 on node puppetslave03.solartis.net
edit retag flag offensive close merge delete

Comments

Can you update this with the exact error message you're getting? Also, did you mean a capital C for your profiles::mysql definition?

Alex Harvey gravatar imageAlex Harvey ( 2016-02-04 10:12:07 -0500 )edit

@Alex Harvey: Attached the error message for your reference.

ArunRaj Rajavel gravatar imageArunRaj Rajavel ( 2016-02-05 09:47:51 -0500 )edit

What about my second question above?

Alex Harvey gravatar imageAlex Harvey ( 2016-02-05 10:38:15 -0500 )edit

@Alex Harvey: I am sorry. It was my typo. Edited now.

ArunRaj Rajavel gravatar imageArunRaj Rajavel ( 2016-02-05 21:58:58 -0500 )edit

Could the problem be that the base mysql module is calling mysql::server as class{} AND your profile is calling it that way, thus causing a conflict? You are getting two class declarations instead of an 'override' as you are expecting. Hard to tell without more code or a complete example

DarylW gravatar imageDarylW ( 2016-02-07 16:13:50 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-02-04 08:40:05 -0500

dannythk gravatar image

Since your root module is "mysql", why do you put "::" in front of it? Could you remove the two colons in the front of your class call.

Class profiles::mysql () {
    class { 'mysql::server':
        config_file => '/opt/arunraj',
        includedir  => true
    }
}

I used profile / role a lot in my environment, I am able to call other classes without duplicate class declaration. Make sure throughout your manifest that you are not calling the same class over and over again.

edit flag offensive delete link more

Comments

1

Fully scoping the class names is not incorrect; and in some situations necessary. That's not the issue.

Alex Harvey gravatar imageAlex Harvey ( 2016-02-04 10:03:21 -0500 )edit

@dannythk : The Colon is used to mention a folder. The class is inside the server folder. This is the only time I have been calling the mysql::server.

ArunRaj Rajavel gravatar imageArunRaj Rajavel ( 2016-02-05 09:50:09 -0500 )edit
0

answered 2016-02-05 22:58:56 -0500

updated 2016-02-05 23:00:46 -0500

I can't reproduce this:

# cat /tmp/foo.pp 
class mysql::server (
  $config_file,
  $includedir,
) {
  notify { "using $config_file and $includedir": }
}

class profiles::mysql () {
  class { '::mysql::server':
    config_file => '/opt/arunraj',
    includedir  => true
  }
}

include ::profiles::mysql

and

# puppet apply /tmp/foo.pp                                                                                                                                                          
Notice: Compiled catalog for centos-66-x64.local in environment production in 0.03 seconds
Notice: using /opt/arunraj and true
Notice: /Stage[main]/Mysql::Server/Notify[using /opt/arunraj and true]/message: defined 'message' as 'using /opt/arunraj and true'
Notice: Finished catalog run in 0.04 seconds

I suspect that the error is to be found elsewhere in your code.

edit flag offensive delete link more

Comments

@Alex Harvey: interesting to see the results. But In my case I am having profiles::mysql and mysql::server are two different modules. When I am trying to call manifest file of profiles::mysql. I am getting the above error. Please guide me to understand the error much deeper

ArunRaj Rajavel gravatar imageArunRaj Rajavel ( 2016-02-06 00:32:11 -0500 )edit
1

Modules are just a way of organising classes. I can't help any further without seeing the rest of your code.

Alex Harvey gravatar imageAlex Harvey ( 2016-02-06 03:16:33 -0500 )edit

@Alex Harvey: https://forge.puppetlabs.com/puppetlabs/mysql I am trying to write our custom profile for the above code. And I would like to configure the values through my profile class instead of the pre existing Mysql::server class also I don't want to affect the existing module. Hope it helps...

ArunRaj Rajavel gravatar imageArunRaj Rajavel ( 2016-02-08 01:25:36 -0500 )edit

Sorry, but it doesn't help. I can see what you are trying to do, and there's nothing wrong in the code you have shared with us. I would need to see the rest of your code.

Alex Harvey gravatar imageAlex Harvey ( 2016-02-08 01:46:21 -0500 )edit

Um, hang on. Are you trying to somehow redefine the mysql::server class that comes in the mysql Forge module?

Alex Harvey gravatar imageAlex Harvey ( 2016-02-08 01:52:30 -0500 )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

Stats

Asked: 2016-02-04 07:29:50 -0500

Seen: 557 times

Last updated: Feb 05 '16