On Sunday, April 21, 2013 8:18:36 AM UTC-5,
max.bri...@gmail.com wrote:
Hi,
Trying to get some understanding on how code should be structured in Puppet. I have a class oracle_java defined to deploy the Java virtual machine on the agents (basically copy of http://log.scalemotion.com/2013/04/oracle-java-under-linux-with-puppet.html). It works fine if i copy the body of the class (omitting the class declaration) within site.pp. But that's no way to do business as you may presume.
No, no way to do business at all.
Now, I put the class under /etc/puppet/manifests/jdk.pp and change site.pp into:
node default{
include jdk
}
Unfortunately, this doesn't work. I keep getting the following error message from the agent:
Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class jdk for ec2-52-221-193-75.compute-1.amazonaws.com-c1421f15-ac06-c6ab-6b5d-95f238bf27c7.
The 'include' function operates on class names, not file names. Unless you have renamed the class, you should be writing "include 'oracle_java'".
In light of that, it should be clear that the issue is largely one of instructing Puppet where to find the definition of the class you want to declare. There are three ways to do that:
- put the whole class definition (not just the body) in site.pp;
- 'import' the class's manifest file into site.pp; or
- correctly put the class into a module so that Puppet can find its manifest automatically.
Is there a way to reference a class in site.pp without creating a module?
Why don't you want to create a module? It's the right thing to do.
The other respondents have covered 'import', which is the direct answer to your question. But don't do that. Creating a module is very simple -- it's basically just a matter of creating a couple of directories. Putting your class into a module is mostly a matter of putting its file in the right place, with the right name. To create a one-class module containing your particular class, simply move /etc/puppet/manifests/jdk.pp to /etc/puppet/modules/oracle_java/manifests/init.pp. Done.
There's room for refinement, however. Your class references a file whose source it assumes can be found on the master, in /etc/puppet/files/. It can continue to do so, but it would be far better to move the source file into the module, too, so that the whole is, um, modular. To do that, move /etc/puppet/files/jdk-7u17-linux-x64.tar.gz to /etc/puppet/module/oracle_java/files/jdk-7u17-linux-x64.tar.gz, and change the line 'source => "puppet:///files/${file_name}",' to 'source => "puppet:///modules/oracle_java/${file_name}",'.
There are further improvements that could be considered, but they go well beyond the scope of your question. You may need a bit more experience with Puppet before you are prepared look into such things.
John