Jesús Couto wrote:
Hi. I'm trying to do a test/proof of concept of Puppet as a tool to manage our systems.
Hello, wow long mail. :)

In our enviroment we have several different instances of apache running on each "webserver" machine, and several instances of tomcat running in our "appservers" machines

I'm trying to duplicate that structure using Puppet on a Ubuntu machine I'm using for testing, to no avail yet.

Isnt any well know recipe to do this? Or at least an idea about how to go to achieve it?

So far what I've done is this:

- Define a class webserver that ensures the apache package is installed and NOT running, and creates a directory for the instances info to be stored

class webserver {
        case $operatingsystem {
                ubuntu: { $web_packages = "apache2" }
        }

        package { $web_packages: ensure => installed }

        service { httpd:
                name => $operatingsystem ? {
                        ubuntu => "apache2",
                },
                ensure => stopped,
                enable => false,
        }
        file {"/etc/webinstances/":
                ensure => directory,
                owner => root,
                group => root,
                mode => 755,
        }
}

- Include that class into a definition of "webinstance" that tries to populate the directory of that instance from the puppet fileserver, and start/stop a "base" service provider with a script generated from a template:

define webinstance(owner,group,ensure = running) {
        include webserver
        file { "/etc/webinstances/$name/":
                owner => $owner,
                group => $group,
                mode => 600,
                ensure => directory,
                recurse => true,
                source => "puppet:///webinstances/$name/",
        }
Sidenote: the above resource will not purge old files.
        file { "/usr/sbin/start_$name.sh":
                owner => root,
                group => root,
                mode => 700,
                content => template("start_instance.erb"),

        }
        file { "/usr/sbin/stop_$name.sh":
                owner => root,
                group => root,
                mode => 700,
                content => template("stop_instance.erb"),
        }
        service { "$name":
                ensure => $ensure,
                provider => base,
                start => "/usr/sbin/start_$name.sh",
                stop => "/usr/sbin/stop_$name.sh",
status => "/usr/sbin/apache2 -f /etc/webinstances/$name/apache2.conf -k sta
rt",
require => [ File["/etc/webinstances/$name"],File["/usr/sbin/start_$name.sh
"],File["/usr/sbin/stop_$name.sh"] ],
        }
}
This sounds sane, with the possible addition of the /etc/webinstances/$name/apache2.conf as a notify resource to restart the service


- every node that needs to have an instance will define it

node staberinde {
        webinstance { "uno":
                owner => root,
                group => root,
                ensure => running,
        }
        webinstance { "dos":
                owner => root,
                group => root,
                ensure => running,
        }
}

... but appart from not getting the scripts to start & stop the instances (it says the scripts "return 1" although I can run them from the prompt without problem:

err: //Node[staberinde]/Webinstance[uno]/Service[uno]/ensure: change from stopped to running failed: Could not start Service[uno]: Execution of '/usr/sbin/start_uno.sh' returned 1: at /etc/puppet/manifests/webinstance-definition.pp:31
The return value of the scripts should be 0. (check for exit statements in the script) Unfortunately the scripts are the fault here and they should return 0 for success and anything else for failure, this is the way puppet figures out if everything went ok or not.
To check the return value of the scripts run them and then echo $? EX:
/usr/sbin/start_uno.sh
echo $?
Also make sure that the status is correct. (try running puppet wile the services are running, and wile not, but I guess they are not since this should install them, right?)

... the other thing that is making me think this is convoluted and wrong is... what if I want the same instance in 2 nodes, as we do? can I use the definition on both nodes with the same parameters and not get an error cause I'm defining the same resource twice?
The only problem is using the same resource twice on the same node. You can apply the same resource for each node you have if you wish.


Silviu

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-us...@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.


Reply via email to