It seems pretty simple thing, and it works on Vagrant, but I can't make it work on a EC2 server.
When:
puppet apply manifests/init.pp
Error:
Could not find class base for s1.ec2.internal at /var/lib/jenkins/jobs/s1/workspace/manifests/init.pp:1 on node s1.ec2.internal
File ./manifests/init.pp:
include base
File ./manifests/base.pp:
class base {
exec { "apt-get update":
command => "/usr/bin/apt-get update",
timeout => 0
}
package { ["vim", "git", "build-essential"]:
ensure => present,
require => Exec["apt-get update"]
}
}
Puppet v2.7.23
Like Felix stated the class base is being looked for in the modules of your puppet manifests. The directory structure of your modules as follows:
$confdir/
|- manifests
|- init.pp <- The file you reference to when executing puppet apply
|- modules
|- base
|- manifests
|- init.pp <- The file containing your base class
What Felix forgot to mention was that there needs to be another manifests directory within the base module directory.
See also https://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html
Usually class base will be found only in a module named base.
Try putting it into modules/base/init.pp instead of manifests/base.pp.
In my case it was a permissions issue - the files were owned by root but I wasn't running puppet with sudo
Related
Just wondering if I have the following puppet file and I would like to split them into separate files. Do I have to create module? Can't I just include them?
node default {
include mysql
}
class mysql {
# Make sure MySQL is ...
notify {"Mysql":}
# installed
package { 'mysql':
require => Exec['apt-update'], # require 'apt-update' before installing
ensure => installed,
}
# and running
service { 'mysql':
ensure => running,
enable => true,
}
}
...
I just want to take out mysql class to be on separate file. How to do this simple thing? Btw I'm using masterless puppet
Edit
Big big apologies, the truth is I was only using puppet without vagrant. But since I'm not a devops expert, when there was a revision on my question to include vagrant I just accepted it. Sorry for the confusion and let me revise my question
Can I do the separation WITHOUT vagrant? If I have to so be it.
Thanks
You can move your mysql class into its own module
you'll end up with something like this
.
├── Vagrantfile
├── puppet
| ├── manifests
| ├──── base.pp
| └── modules
| └── mysql
| └── manifests
| └──── init.pp
Vagrantfile would be like
Vagrant.configure("2") do |config|
<make all your configuration here>
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "base.pp"
puppet.module_path = "puppet/modules"
end
end
end
the base.pp file will only contain
node default {
include mysql
}
and your mysql/init.pp file will contain the mysql class itself
class mysql {
# Make sure MySQL is ...
notify {"Mysql":}
# installed
package { 'mysql':
require => Exec['apt-update'], # require 'apt-update' before installing
ensure => installed,
}
# and running
service { 'mysql':
ensure => running,
enable => true,
}
}
It can be a good idea for module exercise in puppet, but honestly you're more likely to use an existing module and not reinvent the wheel: https://forge.puppet.com/puppetlabs/mysql/2.2.3 will be a good module to use
I am getting a duplicate declaration error when I don't think I should.
I am using the following puppet version
puppet --version
4.3.2
This is the directory structure
./manifests
./manifests/site.pp
./modules
./modules/main
./modules/main/manifests
./modules/main/manifests/init.pp
./modules/main/manifests/sub.pp
site.pp
node default {
include main
include main::sub
}
init.pp
class main {
notice("main")
}
sub.pp
class main::sub {
notice("sub")
}
I run this command
puppet apply --modulepath ./modules manifests/site.pp
It yields this output:
Notice: Scope(Class[Main]): main
Notice: Scope(Class[Main::Sub]): sub
Notice: Compiled catalog for black-pearl.hsd1.il.comcast.net in environment production in 0.82 seconds
Error: Duplicate declaration: Class[Main] is already declared; cannot redeclare
I'm not sure why this happens, perhaps puppet has a main already. When I substituted ryan in for main all was well.
$ find .
.
./manifests
./manifests/site.pp
./modules
./modules/ryan
./modules/ryan/manifests
./modules/ryan/manifests/init.pp
./modules/ryan/manifests/sub.pp
site.pp
node default {
include ryan
include ryan::sub
}
Puppet 4 is a lot stricter about names, and there are a number of reserved names, including main:
Reserved Class Names
The following are built-in namespaces used by Puppet and so must not be used as class names:
main — Puppet automatically creates a main class, which contains any resources not contained by any other class.
See https://docs.puppetlabs.com/puppet/latest/reference/lang_reserved.html
for more
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.
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
I was trying to install zeo service from puppet master in windows agent and I got the following error:
Error: Failed to apply catalog: Could not find dependency Class[Zeo] for Class[Z eo::Install] in PUPPET
I have module called zeo and its manifests init.pp and make.pp and install.pp
But Its failing to reach init.pp and class zeo
# make.pp
class zeo::make {
notify{" make.pp client mass section zope/init.pp": }
require zeo
#....
#....
#....
}
# install.pp
class zeo::install {
notify{"client mass section zope/init.pp ${title}": }
require zeo::make
#....
#....
#....
}
# init.pp
class zeo {
require prerequisite::install
#....
#....
#....
}
Please help me to resolve this
Please debug as:
1) Checkout your module path i.e : puppet config print modulepath
2) Module name i.e zeo should be same as your class name as it is case sensitive.In refrence to your class name i.e "zeo" and module name is "Zeo" (as appeared in error message) .
3) Comment out this line "require prerequisite::install" as we don't know whether prerequisite::install class exists or not.
You did not show where you are calling zeo::install.
So 2 options :
make sure you do not mean require zeo::install instead of require prerequisite::install
Make sure the directories are :
modules
|_ zeo
|- manifests
|- init.pp
|- make.pp
|- install.pp
|_ prerequiste
|- manifests
|- init.pp
|- install.pp