The use case i try to illustrate is when to declare some item (eq
mysqld service) with a default configuration that could be included on
every node (class stripdown in the example, for basenode), and still
be able to override this same item in some specific class (eg
mysql::server), to be included by specific nodes (eg myserver.local)
I illustrated this use case with the example below. But of course,
Puppet parsing fails because the Service[mysql] is included twice. And
of course, class mysql::server
Is there a way to override the Service["mysql"], or mark it as the
main one, or whatever ?
I was thinking about the virtual items and the realize function, but
it only permits apply an item multiple times, not to redefine or
override.
class stripdown {
service {"mysql": enable => "false", ensure => "stopped" }
}
class stripdown {
include mysql::server
Service {"mysql": enable => "false", ensure => "stopped" }
}
Check the language tutorial for overriding. Note that is a big "S" not
a small "s".
class mysql::server {
service { mysqld:
enable => true,
ensure => running,
hasrestart => true,
hasstatus => true,
path => "/etc/init.d/mysql",
require => Package["mysql-server"],
}
}
node basenode {
include stripdown
}
node myserver.local inherits basenode {
include mysql::server # <- boom, fails here
because of Service["mysql"] redefinition
}
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
No, i do not try to use exec to change the change the state of the
service which is -executed- elsewhere (i aggree it would be stupid and
impossible, a ressource can not have two different status at the same
time), but i do use exec to set services that are -declared- elsewhere
in puppet, but not included(executed). So that the state of the
service is the one of the exec. Unfortunately, i had to do that,
because otherwise Puppet would complain at -parsing- time, not execute
time, since it does not want to have the same ressource(here service)
declared twice, even if one is not included for the node, nor be
overriden if not in a child class (and i understand very well the
logic behind that, it makes sense, if we do not consider that we could
assign priorities or precedences on puppet ressources (but then it
could be a mess :-/))
I also checked your solutions, but it does not solve what i wanted
to achieve. What i wanted is per node :
- if i want to include a class (eg mysql::server), then i
include it.
- If it is missing(not included or required by some other
included class), then have the default global stripdown executed.
As i understood, your solution says that if i do not want a
service in a node, then i should include the disabled class (eg
mysql::server::disabled). This is not what i want, what i want is my
nodes definition to be agnostic of what could have been included
previously in the past or may already be present on the server. I do
not want for each node to declare every ressource that exist in my
puppet repo to be disabled (Eg if only 1 node of my 100 needs mysql
running, i do not wish to have to include mysql::server::disabled in
the 99 other nodes definitions. But i want to ensure the mysqld
service is down for these 99 nodes, in case it was running on the node
for whatever reason).
Of course, we need to accept that puppet will try to stripdown
services that are not even installed, but i do not see it as a
problem.
I think this is good general practice of sysadmin to ensure
everything on a linux system that is not needed should be removed,
restricted or disabled (services, users, dir permissions). As we see
here, it seems Puppet can not fullfill this need, except by listing
explicitely and exhaustively what needs to be or not be activated for
each node. So of course, one way or another, there is a place where i
need to tell what should be stripdowned. But i want it to be accepted
as the default -state- of the node, unless specified otherwise by
including a class which redefines some of the ressources that need to
be activated. I do not want my nodes.pp to be 1000000 lines and
unmaintanable.
I understand the meaning of declarative language. I just miss the
fact that i can not declare something like if something is not
included, then apply this whole set of declarations.
-> Unfortunately for me, there might be a way to do this
"default state"/"included state" scheme in Puppet, or by including
ruby or facter or ..., but i am not a puppet expert. This could maybe
be the subject of another thread
> [...]
> I think this is good general practice of sysadmin to ensure
> everything on a linux system that is not needed should be removed,
> restricted or disabled (services, users, dir permissions). As we see
> here, it seems Puppet can not fullfill this need, except by listing
> explicitely and exhaustively what needs to be or not be activated for
> each node. So of course, one way or another, there is a place where i
> need to tell what should be stripdowned. But i want it to be accepted
> as the default -state- of the node, unless specified otherwise by
> including a class which redefines some of the ressources that need to
> be activated. I do not want my nodes.pp to be 1000000 lines and
> unmaintanable.
How about doing it the other way round? Generally include the
stripped-down classes and then include additionally per node the mysql
class which inherits the stripped down class but overwrites the
resources to manage mysql:
node default {
include configsets
}
node mysqlserver {
include configsets::mysqlserver
}
class configsets {
include mysql::server
}
class configsets::mysqlserver {
include config
include mysql::server::present
}
class mysql::server {
package{'mysql-server': ensure => absent }
service{'mysql-server':
ensure => stopped,
enable => false,
require => Package['mysql-server'],
}
}
class mysql::server::present inherits mysql::server {
Package['mysql-server']{ ensure => installed }
Service['mysql-server']{
ensure => running,
enable => true,
}
file{'/etc/my.conf':
source => "...."
notify => Service['mysql-server'],
}
}
Naming convention could be better, but I think this should generally
work. You simply include every resource you manage in the general class
configsets, which gets applied to every node (also due to inheritance,
reinclusion) but include the "present" class in nodes that need it.
> I do not want my nodes.pp to be 1000000 lines and unmaintanable.
I would generally avoid putting too much into nodes. My nodes look like:
node default {
$some_var_1 = 'aaa'
$some_var_2 = 'bbb'
include configsets
}
node foobar {
$some_var_1 = 'foo'
$some_var_2 = 'bar'
include configsets::foobar
}
And all the actual service includes are done in the module called
configesets, which can have further abstraction like node-types, i.e.
physical nodes (class is included depending on the virtual fact) etc.,
inheritance and so on.
Did I miss some circumstances why this shouldn't work?
cheers pete.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAksp8QQACgkQbwltcAfKi383ZwCdHOZO8yYdo6zooR07tgy5OE7/
ZhgAoJzWrZoO2ikcrO/ZRJVLE/fPcufr
=/lYm
-----END PGP SIGNATURE-----
On Dec 17, 2:51 am, Peter Meier <peter.me...@immerda.ch> wrote:
> How about doing it the other way round? Generally include the
> stripped-down classes and then include additionally per node the mysql
> class which inherits the stripped down class but overwrites the
> resources to manage mysql:
[...]
This is precisely what Sliviu recommended, and, as far as I can tell,
it's exactly what Alexandre is asking for. The general approach
demonstrably works, which is why I am confused by Alexandre's claim
that Puppet can't do what he wants.
John
On Dec 16, 9:17 pm, Alexandre <alexandre.fou...@gmail.com> wrote:
[...]
> because otherwise Puppet would complain at -parsing- time, not execute
> time, since it does not want to have the same ressource(here service)
> declared twice, even if one is not included for the node,
Puppet does not exhibit this problem for me. The only way I have been
able to elicit a resource conflict error from Puppet is to have one
node include two classes each declaring a resource of the same type
and name. It is not enough to cause such an error (in my tests)
simply for two classes to define the same resource -- both must be
included in the same node to get the error. If you find differently
then I encourage you to file a bug report.
John
On Dec 16, 9:17 pm, Alexandre <alexandre.fou...@gmail.com> wrote:
> I understand the meaning of declarative language. I just miss the
> fact that i can not declare something like if something is not
> included, then apply this whole set of declarations.
From the glass-half-full department, I'd like to point out that this
is only an issue in the first place because the Puppet language is
rich enough that there can be some uncertainty about whether a
particular class will be included for a particular node.
You cannot solve your problem in the particular way you were trying to
do, but that does not mean that you cannot solve it within Puppet, nor
even that you cannot solve it within Puppet in a concise and
maintainable way. The structure of the Puppet language strongly
encourages modularity, in the sense of putting related logic and
declarations in the same place. If you try to go against that grain,
as it appears you did, then you are indeed likely to become
frustrated. Nevertheless, you may be able to make that approach work
with use of the built-in "defined" function or by writing your own
custom function. I think the alternatives that Silviu and I, and now
Peter, are suggesting are better aligned with with the language
structure, however.
John
On Dec 17, 8:34 am, jcbollinger <John.Bollin...@stJude.org> wrote:
> On Dec 16, 9:17 pm, Alexandre <alexandre.fou...@gmail.com> wrote:
> [...]
>
> > because otherwise Puppet would complain at -parsing- time, not execute
> > time, since it does not want to have the same ressource(here service)
> > declared twice, even if one is not included for the node,
>
> Puppet does not exhibit this problem for me. The only way I have been
> able to elicit a resource conflict error from Puppet is to have one
> node include two classes each declaring a resource of the same type
> and name.
I just had an additional thought about this one: are you putting all
your declarations into classes? Anything that is outside a class
definition is global, so if that file is parsed, such resources (and
variables, etc.) apply to all nodes.
Incidentally, please do not take this as a cue to attempt to influence
global declarations by controlling which files get parsed. You will
drive yourself nuts that way. For the most part, you should just put
everything into classes. There are some uses for global declarations,
but all the ones I can think of have these characteristics:
1) not harmful if applied when unneeded
2) certain to be parsed if needed
Resource parameter defaults can sometimes fall into this category, for
instance.
John
But this was not my original problem. Let's take an example :
1) i want to apply a general linux stripdown
2) i get a server, which had already stuff on it, maybe services
activated but not used, and on which sometimes people get on and
modify things (file permissions, start services, ...)
3) I want to apply the general stripdown to this server, without
having to know what is there and create a special stripdown just for
this server
4) I still want to install or activate services on this server, while
having the general stripdown still active
So far i can do 1), 2) and 3) with puppet, very simply. My problem is
4). All implementations of 4) i saw in this discussion say i have for
each node, specify exactly what i want to disable and enable, so that
if i have 100 nodes, i have to create 100 different stripdown.
While it is easy saying a node what it should include so that it
provides the needed services, it is big task and unmaintanable to
specify exhaustively what nodes should not include. Especially that
these nodes are used by some people that need some priviledges, but do
not always clean after work or are not sysadmins
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
$mysql_enabled = 1
class mysql::server {
service{mysqld: blablabla activate}
}
class stripdown{
if $mysql_enabled == 1 {
service{mysqld: blablabla deactivate}
}
}
node somenode {
include mysql::server
include stripdown
}
So you see in the case above, the parser will fail because service
[mysql] is included and defined twice (of course, since it is grammar
parser and not an AI ;-). But it would have worked if executed
( But i know the whole thing with variables is maybe a wrong
implementation of the problem )
> it was because the case
>
> $mysql_enabled = 1
> class mysql::server {
> service{mysqld: blablabla activate}
> }
>
> class stripdown{
> if $mysql_enabled == 1 {
> service{mysqld: blablabla deactivate}
> }
> }
>
> node somenode {
> include mysql::server
> include stripdown
> }
>
> So you see in the case above, the parser will fail because service
> [mysql] is included and defined twice (of course, since it is grammar
> parser and not an AI ;-). But it would have worked if executed
> ( But i know the whole thing with variables is maybe a wrong
> implementation of the problem )
why don't you include a stripped down mysql class instead of defining
the service twice? I don't get it:
$mysql_enabled = 1
class mysql::stripdown {
service{mysqld: blablabla deactivate}
}
class mysql::server inherits mysql::stripdown{
Service[mysqld]{ blablabla activate}
}
class stripdown{
if $mysql_enabled == 1 {
include mysql::stripdown
}
}
node somenode {
include mysql::server
include stripdown
}
but I don't like this $mysql_enable at all, in your productive setup is
it a fact or do you set the variable?
cheers pete
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAksrUzMACgkQbwltcAfKi39/rQCcC9sRnnfrgmqH4uKAPZu1iYlh
bnMAn3tc2KsZDGgA9uWDBw3GrdwriYHy
=NuYW
-----END PGP SIGNATURE-----
On Dec 17, 9:19 pm, Alexandre <alexandre.fou...@gmail.com> wrote:
> it was because the case
>
> $mysql_enabled = 1
> class mysql::server {
> service{mysqld: blablabla activate}
>
> }
>
> class stripdown{
> if $mysql_enabled == 1 {
> service{mysqld: blablabla deactivate}
> }
>
> }
>
> node somenode {
> include mysql::server
> include stripdown
>
> }
>
> So you see in the case above, the parser will fail because service
> [mysql] is included and defined twice (of course, since it is grammar
> parser and not an AI ;-). But it would have worked if executed
> ( But i know the whole thing with variables is maybe a wrong
> implementation of the problem )
I agree that variables are not likely constitute a viable approach to
solving this problem. I'm also not all that enthusiastic about the use
of a general stripdown, but that's a personal preference thing. Since
you seem to be intent on that manner of solution, have you tried
something along these lines:
class stripdown {
# turn off everything we care about managing
service { "mysqld": <deactivate> }
service { "apache": <deactivate> }
...
}
class mysql::server inherits stripdown {
Service ["mysqld"] { <activate> }
}
class apache::server inherits stripdown {
Service ["apache"] { <activate> }
}
node foo {
include stripdown
}
node bar {
include stripdown
include mysql::server
}
node baz {
include stripdown
include mysql::server
include apache::server
}
In other words, all your some_facility::server classes inherit from
the same general stripdown and override different (that's important)
resources. Each node then includes the stripdown and the service-
specific classes for those services it should run.
On Dec 17, 9:08 pm, Alexandre <alexandre.fou...@gmail.com> wrote:
> 4). All implementations of 4) i saw in this discussion say i have for
> each node, specify exactly what i want to disable and enable, so that
> if i have 100 nodes, i have to create 100 different stripdown.
I think the result is rather that if you have 100 different *services*
you want to manage via Puppet, then you need a stripdown for each
one. And any way around that's true; it's merely a question of
whether you put all those services' stripdowns in the same class or in
separate classes. You probably have a lot fewer than 100 services.
Personally, if I am interested in the mysql service, then for each
node I would prefer to see one of:
node foo {
include mysql::server
...
}
or
node foo {
include mysql::server::disabled
...
}
or maybe
node foo {
include mysql::server::absent
...
}
You prefer to not be explicit about the latter two cases, and that's
fine, but it doesn't change the number of different combinations of
services your various nodes offer.
> While it is easy saying a node what it should include so that it
> provides the needed services, it is big task and unmaintanable to
> specify exhaustively what nodes should not include.
How maintainable it is depends in part on how many distinct
configurations you need to manage. Do be aware that nodes that are
configured identically do not need separate entries in the node list:
node node1,
node2 {
include mysql::server
}
If you have more than a handful of distinct configurations, though,
then you might be well served by an external node classifier. That's
a program you provide that Puppet uses to dynamically determine which
classes should be included for each node.
John
First of all, Alexandre, you might feel more at home with bcfg2. Bcfg2 by
default manages *everything*, and tells you if something appears that is
unmanaged, forcing you to either manage it or remove it. We looked at bcfg2,
and whereas I liked its model, the puppet community is better, and bcfg2 uses
XML files for configuration *shudder*.
That is a feature I'd love to see in puppet. If unknown and new things appear
on one of my systems, I'd love to know about it. That way I can either decide
to add it to a manifest, or remove it.
That, to me, is better than applying a general stripdown. A general stripdown
(other than "remove everything not explicitly managed") doesn't deal with the
unknowns, and the "remove everything not explicitly managed" doesn't allow for
emergency fixes.
tl;dr: I want to know when *anything* on my system changes, puppet doesn't let
me do that.
Cheers,
Eric
> --
>
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
>
>
--
Eric Gerlach, Network Administrator
Federation of Students
University of Waterloo
p: (519) 888-4567 x36329
e: eger...@feds.uwaterloo.ca
Generally I like the idea, but I didn't yet think of it in every detail.
maybe it could be a bit more elaborated and then a feature request
could be filed?
cheers pete