Dan Rubio
Dan Rubio

Reputation: 4897

Could not find declared class postgresql::server Puppet

I am trying to install an instance of postgresql9.4 on a vagrant box using Puppet. So far, I am not enjoying my time with puppet and the documentation on its site. So far I'm attempting to patch along from different tutorials and the Postgresql Puppet Forge official documentation.

What I've done:

  1. puppet module install puppetlabs-postgresql

  2. I've created a /etc/puppet/modules/postgresql/manifests/init.pp file

  3. I have placed this code in the init.pp file:

     class { 'postgresql::server':
       ip_mask_deny_postgres_user => '0.0.0.0/32',
       ip_mask_allow_all_users    => '0.0.0.0/0',
       listen_addresses           => '*',
       ipv4acls                   => ['hostssl all johndoe 192.168.0.0/24 cert'],
       postgres_password          => 'TPSrep0rt!',
     }
    

The error I receive is this:

    Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Could not find declared class postgresql::server at /etc/puppet/modules/postgresql/manifests/init.pp:7 on node vagrant-ubuntu-trusty-64.bbf.local
Wrapped exception:
Could not find declared class postgresql::server
Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Could not find declared class postgresql::server at /etc/puppet/modules/postgresql/manifests/init.pp:7 on node vagrant-ubuntu-trusty-64.bbf.local

I am getting very frustrated with Puppet, I am trying to follow along with 'Deploying Rails' and the offical forge site to get this to work but to no avail.

My frustration with puppet is that the site doesn't specify where to put anything. From tutorials, I've placed my puppet code in init.pp but the postgresql has repo.pp, server.pp etc. etc. and it doesn't tell you where to place the puppet code. Could someone please assist me?

Upvotes: 3

Views: 1122

Answers (1)

John Bollinger
John Bollinger

Reputation: 180201

So far, I am not enjoying my time with puppet and the documentation on its site. So far I'm attempting to patch along from different tutorials and the Postgresql Puppet Forge official documentation.

I can't speak to the unspecified tutorials you've been following, but the documentation of Puppet's own Postgresql module assumes that you are already conversant with the Puppet language and mode of operation. Myself, I've always thought that Puppet's documentation was pretty good, even before the commercial version was released.

You could consider taking the official VM-based tutorial, but ultimately I recommend reading (or at least skimming) the Language Reference. If you plan to write your own modules, and most users do, then you should also be aware of the Type Reference. Even if you don't plan to write your own modules, you'll be working with modules, so it is useful to skim the section on module fundamentals. There's more that could be useful, but that should be plenty to get you off to a good start.

My frustration with puppet is that the site doesn't specify where to put anything.

The "Basics" chapter of the Language Reference addresses the first part of that:

Puppet always begins compiling with a single manifest (which may be broken up into several pieces), called the “site manifest” or “main manifest.” See the reference page on the main manifest for details about this special file/directory.

The linked page goes into some detail, largely because in a master / agent setup there's a fair amount of flexibilty and several options. If you're using puppet apply, however, then the main manifest is simply whatever file you designate on the puppet command line. A class declaration such as you presented should go into your main manifest, possibly inside a node block, or into the definition of another class, in some module, that will directly or indirectly be declared in your main manifest. As Perl aficionados are prone to say, "There's more than one way to do it."

I emphasize the distinction between a class declaration and a class definition. The former says, roughly, "the named class should be applied to the target node", whereas the latter describes what it means to apply the class to a node. You can consider these analogous to a function call on one hand and the function body on the other. Since you're trying to use a class from a third-party module, the latter should be part of the module. Supposing that your Puppet install is in /etc/puppet, the whole /etc/puppet/modules/postgresql directory belongs to the module implementation, and you should not be putting anything there. In that case, the module tool should have installed the definition of class postgresql::server in /etc/puppet/modules/postgresql/manifests/server.pp.

I cannot provide you specifics on what you should do because you have not provided some of the essential details, especially whether you're running the agent or using puppet apply. There are also a few differences between Puppet 3 and Puppet 4 that might be relevant (default installation location, for example). Nevertheless, I hope this has gotten you pointed inn the right direction.

Upvotes: 1

Related Questions