This is my manifest:
class capstone() {
include apache
include mysql
class {'apache::vhost':
port => 80,
docroot => '/var/www/wordpress',
}
include 'apache::mod::php'
class {'mysql::server' :
root_password => 'foo',
override_options => {
'mysqld' => { 'max_connections' => '1024' },
}
}
class {'mysql::bindings' :
php_enable => true
}
}
I wrote this in modules/capstone/manifests/init.pp
Inside modules, I have stdlib, apache, concat, capstone, mysql, wordpress which are all downloaded except capstone.
My error is:
Error: ERROR: This class has been deprecated and the functionality moved
into mysql::server. If you run mysql::server without correctly calling
mysql:: server with the new override_options hash syntax you will revert
your MySQL to the stock settings. Do not proceed without removing this
class and using mysql::server correctly.
If you are brave you may set attempt_compatibility_mode in this class which
attempts to automap the previous settings to appropriate calls to
mysql::server at /root/radiant/modules/mysql/manifests/init.pp:89 on node kim.puppetlabs.vm
Error: ERROR: This class has been deprecated and the functionality moved
into mysql::server. If you run mysql::server without correctly calling
mysql:: server with the new override_options hash syntax you will revert
your MySQL to the stock settings. Do not proceed without removing this
class and using mysql::server correctly.
If you are brave you may set attempt_compatibility_mode in this class w
I have googled around and have followed the suggestions in other links but I still get the same error. Not sure where I have done wrong.
Please advise.
Two mistakes:
1) do not include mysql
2) did not state the vhosts name correctly
This is the working manifest:
class capstone() {
include apache
include apache::mod::php
apache::vhost { 'wordpress.example.com':
port => 80,
docroot => '/var/www/wordpress',
}
class {'mysql::server' :
root_password => 'foo',
override_options => {
'mysqld' => { 'max_connections' => '1024' },
}
}
class {'mysql::bindings' :
php_enable => true
}
}
Related
So I have a fully functional 'ldap' class.
Now I want to do some stuff for certain users in my ldap directory.
I do this in a new 'users' module, by first making a new defined_type:
define users::admin (
String $sshkey
) {
file {"/home/${title}":
ensure => directory,
owner => $title,
group => 'root',
require => Class['ldap']
}
...
}
Then I use this defined type in my 'users' module's init.pp:
class users {
users::admin {'ldt':
sshkey => 'mysshkey',
}
}
But when I try to use 'pdk test unit' on this, I get the following error:
failed: rspec: ./spec/classes/users_spec.rb:8: error during compilation:
Could not find resource 'Class[Ldap]' in parameter 'require'
(file: ~/Projects/puppet/modules/users/spec/fixtures/modules/users
/manifests/admin.pp, line: 15) on node <mycomputer>
For completeness's sake, here's my admin_spec.rb (barely changed from the pdk default):
require 'spec_helper'
describe 'users::admin' do
let(:title) { 'namevar' }
let(:params) do
{
'sshkey' => ''
}
end
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }
it { is_expected.to compile }
end
end
end
I tried setting my .fixtures.yml as follows, but that didn't help:
fixtures:
symlinks:
ldap: "#{source_dir}"
Any idea on what I'm doing wrong?
EDIT: changed my .fictures.yml to:
fixtures:
symlinks:
ldap: "#{source_dir}/../ldap"
Heck I even manually added a symlink to my ldap module in the spec/fixtures/modules folders. Still the same error.
So it turns out the error had nothing to do with rspec or anything.
I just needed to 'include ldap' in my actual puppet code.
I am just learning Puppet (we have Puppet Enterprise locally). I am trying to understand the "roles and profiles" pattern. Please pardon any nomenclature slip ups.
How do I create a role with multiple instances of a profile, where the profile instances differ only by parameter? I'm guessing Hiera fits into this somewhere but I'm not exactly sure how.
For example:
Puppetfile:
mod 'puppetlabs-apache', '2.3.0'
apache.pp profile
class profile::apache (
String $port = '80',
) {
class { 'apache':
listen => $port,
}
}
twoapaches.pp role
class role::twoapaches {
include profile::apache
include profile::apache
}
I want an instance of the twoapaches role to have an apache at ports 90 and 100 - how do I do that?
You actually can't use classes like that in Puppet; a class can only be declared once-per-node.
You probably need some of the defined types in the puppetlabs/apache module. Defined types are used when you need to declare a user-defined "resource" more than once on a single node.
E.g. profile might be:
class profile::two_vhosts {
apache::vhost { 'ip1.example.com':
ip => ['127.0.0.1','169.254.1.1'],
port => '80',
docroot => '/var/www/ip',
}
apache::vhost { 'ip2.example.com':
ip => ['127.0.0.1'],
port => '8080',
docroot => '/var/www/ip',
}
}
And the role might be:
class role::two_vhosts {
include profile::two_vhosts
include profile::other_stuff
...
}
If you needed to then pass the ports in, you might have:
class profile::two_vhosts (
String $ip1_port,
String $ip2_port,
) {
apache::vhost { 'ip1.example.com':
ip => ['127.0.0.1','169.254.1.1'],
port => $ip1_port,
docroot => '/var/www/ip',
}
apache::vhost { 'ip2.example.com':
ip => ['127.0.0.1'],
port => $ip2_port,
docroot => '/var/www/ip',
}
}
You could then have your role as:
class role::two_vhosts {
class { 'profile::two_vhosts':
ip1_port => '80',
ip2_port => '8080',
}
include profile::other_stuff
...
}
But in practice people use the Automatic Parameter Lookup feature here in conjunction with Hiera (ref).
I would use Hiera also for the parameters. This way you can easily change ports if needed and you comply with the rule of no putting classes inside the roles:
class role::two_vhosts {
include profile::two_vhosts
include profile::other_stuff
...
}
Hiera configuration when including the role would be something like this:
profile::two_vhosts::ip1_port: '80'
profile::two_vhosts::ip2_port: '8080'
I'm trying to manage my hosts file on a Windows machine using Puppet and Hiera. My problem is that I have never really used Hiera and I'm struggling with parsing the data content into a proper format.
The relevant section in hieradata/hiera.yaml looks like this:
myhosts : [
'host1 1.2.3.4',
'host2 2.3.4.5',
'host3 3.4.5.6']
I have code that uses a host module, but it also depends on a class that I don't have, so naturally it doesn't work.
class hosts::module (
$myhosts = hiera('myhosts'),
)
{
define update_hosts {
$value = split($name,' ')
host {
"${value[0]}" : ip => "${value[1]}",
}
}
update_hosts { $myhosts :; }
}
I have tried using the file resource instead of the host resource, and also tried doing it without any class, but for some reason I am getting this error
Error: Could not retrieve catalog from remote server: Error 500 on SERVER:
Server Error: Evaluation Error: Error while evaluating a Resource Statement,
Evaluation Error: Error while evaluating a Resource Statement, Duplicate
declaration: File[C:\Temp\tmp.txt] is already declared in file
/etc/puppetlabs/code/environments/production/manifests/site.pp:4; cannot redeclare
at /etc/puppetlabs/code/environments/production/manifests/site.pp:4
at /etc/puppetlabs/code/environments/production/manifests/site.pp:4:1
at /etc/puppetlabs/code/environments/production/manifests/site.pp:10 on node puppet-agent
As you can see, it claims that I have a duplicate declaration, but the weird thing is that it says it has a problem with the same line. It thinks it's declaring the same thing twice for some reason.
This is the code I have now (I know it won't work but the error doesn't really sound related)
define hosts_update($content) {
file { 'C:\Temp\tmp.txt' :
ensure => file,
content => $content,
}
}
hosts_update{ hiera('myhosts'):
content => split($name," "),
}
Any idea how to do this right?
fixed it.
site.pp
include update_hosts
init.pp
class update_hosts::host
(
$hosts = hiera('hosts_list'),
)
{
update_host { $hosts :; }
}
host.pp
define update_host {
$value = split($name,' ')
host {
"${value[0]}" : ip => "${value[1]}",
target => "C:/Windows/System32/drivers/etc/hosts"
}
}
Puppet Version: 3.2.4 (Puppet Enterprise 3.0.1)
In order to better support nagios cfg_dir and cfg_file directives in the config file, I've created the following class(es), one for each option:
# Class to add a cfg_dir to the nagios configuration file
class nagios::server::cfg_dir (
$config_dir,
$nagios_user,
$nagios_group,
$nagios_config_file = '/etc/nagios3/nagios.cfg',
)
{
# Build the config dir
file {$config_dir:
ensure => directory,
owner => $nagios_user,
group => $nagios_group,
mode => '0750',
}
# Append cfg_dir=$config_dir path to nagios.cfg file
augeas { "cfg_dir=$config_dir in $nagios_config_file":
incl => "$nagios_config_file",
lens => 'NagiosCfg.lns',
changes => "set cfg_dir/[last()+1] ${config_dir}",
require => File[$nagios_config_file],
}
}
Trying to use this construct inside nagios::server, I have this:
# Set up config directories
each($cfg_dir) |$x| {
class { 'nagios::server::cfg_dir':
config_dir => $x,
nagios_user => $nagios_user,
nagios_group => $nagios_group,
nagios_config_file => $nagios_config_file,
}
}
Which should, in theory, execute the class instantiation for each path passed in to the nagios::server class like so:
class{'::nagios::server': cfg_dir => ['/etc/nagios.d','/etc/nagios/objects'] }
However, I run into this issue:
Error: Could not match |$x| at /tmp/vagrant-puppet-1/modules-2/nagios/manifests/server.pp:181 on node localhost.localdomain
Can someone provide a working example of each in use? Am I expecting too much from this built-in puppet function?
Aside from a few of the code grammar issues above, I've found that this construct is only evaluated in the future parser:
puppet apply --parser=future --modulepath ...
http://docs.puppetlabs.com/puppet/latest/reference/experiments_lambdas.html
Still getting past other dependency issues. What pattern would I use to support this with the current parser instead of future? A custom function?
The answer to my follow-up question is to use defined types:
http://docs.puppetlabs.com/learning/definedtypes.html
Simply changing the above code from a class to a define and assign $config_dir the value from $target,
define nagios::server::cfg_dir (
$config_dir = $target,
$nagios_user,
$nagios_group,
$nagios_config_file = '/etc/nagios3/nagios.cfg',
){...
you can use constructs such as:
nagios::server::cfg_dir { '/etc/nagios.d/', '/etc/nagios/objects':
nagios_user => 'nagios',
nagios_group => 'nagios'
}
This solves the issue for me.
We are attempting to use the camptocamp/puppet-nagios module, but we're running into a packaging naming conflict between vanilla CentOS repositories and RPMForge/RepoForge. The nsca daemon in CentOS provides the same service as the nagios-nsca package in RepoForge. In attempt to install the RepoForge package yet satisify the Package requirement for nsca resource, I've added this to my node definition:
include ::nagios
package { 'nagios-nsca': ensure => installed, alias => 'nsca', }
include ::nagios::nsca::server
The resulting error is:
Error: Duplicate declaration: Package[nsca] is already declared in
file /tmp/vagrant-puppet-1/modules-0/role/manifests/nagios.pp:45;
cannot redeclare at
/tmp/vagrant-puppet-1/modules-2/nagios/manifests/nsca/server.pp:24
The next test was to use order and calling the class directly from the node:
include ::nagios
package { 'nagios-nsca': ensure => installed, alias => 'nsca', } ->
class {'::nagios::nsca::server' : }
The code in question inside the nagios/manifests/nsca/server.pp file is:
class nagios::nsca::server(
$decryption_method = pick($nagios_nsca_decryption_method, '0'),
) {
include ::nagios::params
# variables used in ERB template
$basename = $nagios::params::basename
if !defined (Package['nsca']) {
package {'nsca':
ensure => installed;
}
}
Any insight as to what's happening here? I can always fork the camptocamp/puppet-nagios code and force the behavior we want, but I'd rather not.
Due to ! defined(Package['title']) not working as expected. I fixed this by giving nagios::nsca::server an additional parameter of nsca_package, including a default value of nsca to preserve current behavior:
--- a/manifests/nsca/server.pp
+++ b/manifests/nsca/server.pp
## -11,6 +11,7 ##
#
class nagios::nsca::server(
$decryption_method = pick($nagios_nsca_decryption_method, '0'),
+ $nsca_package = 'nsca'
) {
include ::nagios::params
## -20,6 +21,7 ## class nagios::nsca::server(
if !defined (Package['nsca']) {
package {'nsca':
+ name => $nsca_package,
ensure => installed;
}
}
Use for this new parameter would be:
node 'my-nagios-server.local' {
include ::nagios
class {'::nagios::nsca::server': nsca_package => 'nagios-nsca', }
}