Problem dealing with multi role servers/manifests. resource already declared.

201 views
Skip to first unread message

trey85stang

unread,
Jun 20, 2012, 6:20:38 PM6/20/12
to Puppet Users
Hey All,


Im running into a road block with a server that is going to to be
multi role.

Example:

I want to run a nagios server and a repo server on one box.

My nagios manifest has two services defined:

class nagios::server {
...
service { nagios:
ensure => running,
...
}

service { httpd:
ensure => running
...
}
...
}


Now I also want to assign my reposerver manifest to a server already
running the nagios manifest

class repo::server {
...
service { httpd:
ensure => running
}
...
}


Now in each case I have files where httpd is notified to refresh...
Is there a way to work around this without creating a custom module
just for this one case? As you can see from the below error message I
tried changing the name and using an alias.. but it does not like that
either.

There error message:
Could not retrieve catalog from remote server: Error 400 on SERVER:
Puppet::Parser::AST::Resource failed with error ArgumentError: Cannot
alias Service[reposerver-httpd] to ["httpd"] at /etc/puppet/
environments/dev/modules/repo/manifests/init.pp:113; resource
["Service", "httpd"] already declared at /etc/puppet/environments/dev/
modules/nagios/manifests/init.pp:217 at /etc/puppet/environments/dev/
modules/opservers/manifests/init.pp:113 on node mynode.com

Walter Heck

unread,
Jun 21, 2012, 2:10:08 AM6/21/12
to puppet...@googlegroups.com
On Thu, Jun 21, 2012 at 6:20 AM, trey85stang <trey8...@gmail.com> wrote:
> Now in each case I have files where httpd is notified to refresh...
> Is there a way to work around this without creating a custom module
> just for this one case? As you can see from the below error message I
> tried changing the name and using an alias.. but it does not like that
> either.
The combination of Resource type and title needs to be unique for a
single node. However, you can also not have two resources managing the
same thing (in this case the http service). In order to get around
this properly, you'd need to extract httpd into a module of it's own
(where it belongs imho anyway) and refer to the service from both your
nagios and your repoman manifests.

If you don't want to make that module a full fledged apache (or
whichever webserver you are running), then that's okay. Just keep it
very simple, but do extract it. You can always expand it later.

kind regards,

--
Walter Heck

--
Check out my startup: Puppet training and consulting @ http://www.olindata.com
Follow @olindata on Twitter and/or 'Like' our Facebook page at
http://www.facebook.com/olindata

trey85stang

unread,
Jun 21, 2012, 10:01:24 AM6/21/12
to puppet...@googlegroups.com
Sounds good,  not the way I was hoping to have to do it.. but that will work.

trey85stang

unread,
Jun 21, 2012, 10:24:59 AM6/21/12
to puppet...@googlegroups.com
Actually,  one more question to spawn off this...  Is there  a way in my nagios/repo class to say if you have this class go ahead and assign yourself to my new services:httpd class?  Can that be done with inheritance?  I have never used inheritance so I am not sure.

trey85stang

unread,
Jun 21, 2012, 10:32:18 AM6/21/12
to puppet...@googlegroups.com
Hell... I just tried it an it works fine.  At least that way I dont have to go back and assign all my servers to the new httpd module.

Nick Fagerlund

unread,
Jun 21, 2012, 6:19:32 PM6/21/12
to puppet...@googlegroups.com


On Thursday, June 21, 2012 7:24:59 AM UTC-7, trey85stang wrote:
Actually,  one more question to spawn off this...  Is there  a way in my nagios/repo class to say if you have this class go ahead and assign yourself to my new services:httpd class?  Can that be done with inheritance?  I have never used inheritance so I am not sure.


You shouldn't need inheritance -- you can do this with plain old "include services::httpd". Unlike when you declare a resource, include can be safely used multiple times on a single class, pretty much for this exact reason.

trey85stang

unread,
Jun 22, 2012, 10:48:49 AM6/22/12
to puppet...@googlegroups.com

Ok,  even better!

Thank you!
Reply all
Reply to author
Forward
0 new messages