Can not find class during Puppet apply - puppet

My puppet structure is as follows
/puppet
/manifests
/nodes
redis.pp
site.pp
/modules
The site.pp resembles
class base {
include ml-basefw
include ml-users
include ml-filelimits
include repoforge
include epel
class { 'ml-yumrepo':
base_url => "http://${puppet_server}/yumrepo"
}
}
import 'nodes/*.pp'
node default {
include base
}
When I run
puppet apply --modulepath=/puppet/modules:/puppet/manifests --noop --debug /puppet/manifests/nodes/redis.pp
I receive
Error: Could not find class base for redis-1.test.ml.com on node redis-1.test.ml.com
Is there something non-standard about my file layout that precludes me from using apply?
I am not the maintainer of the puppet module so I am not able to alter the file structure or layout.
There are numerous related questions but I wasn't able to relate them to the problem that I am having.
Edit1 : Adding redis.pp
node /^redis-\d+(.stage)?(.test)?(.aws)?.ml.com$/ {
include base
include epel
class { 'redis':
package_ensure => '2.8.15-1.el6.remi',
service_ensure => 'running',
conf_bind => '0.0.0.0',
conf_port => '6379',
}
firewall { '176 allow port 6379 for redis traffic':
chain => 'INPUT',
state => ['NEW'],
dport => '6379',
proto => 'tcp',
action => 'accept'
}
}

What happens when you run puppet apply against your site.pp file instead? You probably don't have a node definition in your redis.pp file (nor should you).

This does in fact look a little messy and convoluted.
What you want is
an actual base module
defining class base in /puppet/modules/base/manifests/init.pp
You should also loose the import statement by arranging your manifests better. If your version of Puppet is recent enough (I think 3.6+), just see the docs.

fist of all, puppet have the entry manifest file.
in master mode, the entry is site.pp and puppet deprated deprecated it from version 3.5, it started auto imported all manifest files in specified directory.
in apply mode, the entry is specified file in your command.
so it works fine in your production environment, puppet master read site.pp(contains class base) and import nodes/*.pp(redis.pp, contains node definition). but when you use "puppet apply /puppet/manifests/nodes/redis.pp", puppet just read redis.pp, no anyone tell puppet where the base class is.

Related

puppetlabs-dhcp: Could not find dependency File[/etc/dhcp/dhcpd.conf]

I'm pretty new to puppet and I'm trying to use the module puppetlabs-dhcp (v0.3.0) with puppet master/agent v3.7.2. I'm using a very simple class declaration following the example given by the README file.
When I try to run the class on the node using puppet agent -t the run fails with the error
Error: Failed to apply catalog: Could not find dependency File[/etc/dhcp/dhcpd.conf] for Service[isc-dhcp-server] at /etc/puppet/modules/dhcp/manifests/init.pp:173
I tried adding a file resource before the dhcp class declaration but the file stays blank. None of the configurations are taken into account.
I checked the dependencies:
concat > 1.0.1 (using 2.0.2)
stdlib > 2.0.0 (using 4.13.1)
Here is the dhcp portion of the node in site.pp:
class {'dhcp':
dnsdomain => [
'jecks.lab',
'0.0.10.IN-ADDR.ARPA',],
nameservers => ['10.0.0.2'],
ntpservers => ['us.pool.ntp.org'],
interfaces => ['eth0','eth1'],
}
dhcp::pool{'ops.jecks.lab':
network => '10.0.0.0',
mask => '255.255.255.0',
range => ['10.0.0.100','10.0.0.254'],
gateway => '10.0.0.1',
}
dhcp::host {'debian-main':
mac => 'xxxxxxxxxxxxxx',
ip => '10.0.0.3',
}
What am I doing wrong? I assumed the dhcpd.conf file was created using concat from the parameters given in the class declaration.
This is a bug in puppetlabs-dhcp 0.3.0 when using concat 2.x that was fixed in 0.4.0. Using a newer version of the dhcp module or downgrading concat to 1.x would fix it.
Note that the puppetlabs-dhcp module moved to the Vox Pupuli community organisation a while ago, so you can find updates at puppet/dhcp on the Forge. The latest at the time of writing is 1.0.1, rather than 0.3.0.

modules not found in standalone puppet

I am starting the journey with Puppet.
I have installed stand-alone puppet on RHEL 6.0 (NO master/agent, just stand-alone)
Puppet version is 4.5.2
I have created a module /opt/puppetlabs/puppet/modules/common/manifests/init.pp as
class user {
user { 'wasadmin':
ensure => present,
comment => 'wasadmin user',
home => '/home/wasadmin',
managehome => true
}
}
my site.pp is here as /opt/puppetlabs/puppet/manifests/site.pp
node "CI-TEST-POC" {
include user
}
modulepath = /etc/puppetlabs/code/environments/production/modules:/etc/puppetlabs/code/modules:/opt/puppetlabs/puppet/modules
when I execute with and without --modulepath, I am still getting the same error
root#CI-TEST-POC manifests# puppet apply site.pp
Error: Evaluation Error: Error while evaluating a Function Call, Could not find class ::user for ci-test-poc.corp.aal.au at /opt/puppetlabs/puppet/manifests/site.pp:2:4 on node ci-test-poc.corp.aal.au
root#CI-TEST-POC manifests# puppet apply site.pp --modulepath ../modules
Error: Evaluation Error: Error while evaluating a Function Call, Could not find class ::user for ci-test-poc.corp.aal.au at /opt/puppetlabs/puppet/manifests/site.pp:2:4 on node ci-test-poc.corp.aal.au
I have created a module /opt/puppetlabs/puppet/modules/common/manifests/init.pp as
class user {
The problem lies here, as Puppet requires that the layout of manifests matches the name of the classes/defines within them to help it quickly and correctly find the right file.
For your user class, it should be defined in /opt/puppetlabs/puppet/modules/user/manifests/init.pp.

puppet apply 'could not find class'

This is a pretty simple problem, and I have read a number of suggested solutions, but I still can't get puppet apply to import the git::config class. Here is my file setup:
I import the git module via nodes.pp:
#/etc/puppet/manifests/nodes.pp
node default {
}
include git
site.pp imports nodes.pp:
#/etc/puppet/manifests/site.pp
import 'nodes.pp'
The git module is defined as follows:
#/etc/puppet/modules/git/manifests/init.pp
class git {
include git::install
include git::config
}
class git::install{
package {'git': => present }
}
and the config file:
#/etc/puppet/modules/git/manifests/config.pp
define git::config{
[some code here]
}
When I run puppet apply, puppet does not find the git::config class:
sudo puppet apply --modulepath=/etc/puppet/modules /etc/puppet/manifests/site.pp
Error: Could not find class git::config for xxxx on node xxxx.
The original module was puppetlabs-git (same folder structure), but I have recreated the error using the simplified file structure (above).
Update 1
Typo above, the git config.pp and init.pp are in folder /modules/git/manifests and the config.pp file reads 'define git::config'
You cannot call include on git::config. git::config is a defined type, not a class. The syntax to use a defined type is as follows:
git::config { 'the_name_var':
param1 => 'foo',
param2 => 'bar'
}
Hope this helps
Your puppet code structure is wrong. You need move your pp file to manifests folders.
/etc/puppet/modules/git/init.pp
/etc/puppet/modules/git/config.pp
to
/etc/puppet/modules/git/manifests/init.pp
/etc/puppet/modules/git/manifests/config.pp

Puppet Could not find dependency Class

I am trying to pull things out into roles and profiles and am having an issue. I am using puppet apply for all of this as I am using it to finish setting up my Puppet Master. If I define my node in site.pp as shown here:
[root#puppet puppetdbsetup]# cat manifests/site.pp
node 'puppet' {
include ::roles::puppetmaster
}
I get this error:
[root#puppet puppetdbsetup]# puppet apply manifests/site.pp --environmentpath /etc/puppet/environments --environment puppetdbsetup --noop
Notice: Compiled catalog for puppet.belkin in environment puppetdbsetup in 1.29 seconds
Error: Could not find dependency Class[Puppet::Install] for File[/etc/puppet/hiera.yaml] at /etc/puppet/environments/puppetdbsetup/modules/p
uppet/manifests/master.pp:31
If I run puppetmaster.pp (shown below) with puppet apply directly it doesn't throw the same error.
[root#puppet puppetdbsetup]# cat modules/roles/manifests/puppetmaster.pp
class roles::puppetmaster {
#include profiles::base
include profiles::puppet::master
}
Can anyone tell me why this is and how to fix it? As a side note, all three modules referenced here are hand written... none are Forge modules.
Update 1
Here is my puppet::install class:
[root#puppet puppetdbsetup]# cat modules/puppet/manifests/install.pp
class puppet::install {
package { 'puppet':
ensure => present,
}
}
Somewhere in your manifest, you are declaring a File[/etc/puppet/hiera.yaml] that depends on Class[Puppet::Install], like
file { '/etc/puppet/hiera.yaml': require => Class['puppet::install'] }
or so
Class['puppet::install'] -> file { '/etc/puppet/hiera.yaml': ... }
or something in that vein.
What you are lacking is the actual declaration of the class either via
include puppet::install # nice!
or
class { 'puppet::install': } # please don't
If in doubt, add the include line near the file declaration. It is usually safe to include a class multiple times.
If you apply puppetmaster.pp directly, you're just defining the class not applying it.
You need to do puppet apply -e 'include ::roles::puppetmaster' to be comparible.
The other error is probably caused by modules/puppet/manifests/install.pp not existing, or the class definition in the file not starting with
class puppet::install (
....
....
) {

Why can't puppet find my class?

I'm trying to implement the recipe found here https://github.com/puppetlabs/puppetlabs-firewall#readme and I appear to be making a rookie puppet mistake I can't see. I have a module called mwsettings which itself can be found okay (the mwsettings/init.pp stores a helper for loading some templates and that works), but the following code in my site.pp
Firewall {
notify => Exec['persist-firewall'],
before => Class['mwsettings::postfirewall'],
require => Class['mwsettings::prefirewall'],
}
Blows up with
Error: Failed to apply catalog: Could not find dependency Class[Mwsettings::Prefirewall] for Firewall[100 accept mysql - XXXXXXXX]
when my code later in site.pp invokes
firewall { "100 accept mysql - $name":
proto => 'tcp',
action => 'accept',
dport => 3306,
source => $name,
}
But, it appears I have the manifest set up properly for prefirewall:
# cat modules/mwsettings/manifests/prefirewall.pp
class mwsettings::prefirewall {
Firewall {
require => undef,
}
<snip>
Am I missing something incredibly trivial here? Since it's my first rodeo with puppet, I'm not even entirely sure how to debug this.
Thanks!
You are referring to a class that you haven't declared.
If you add this it should work :
include mwsettings::prefirewall
include mwsettings::postfirewall

Resources