I try to write a puppet configuration in order to install lamp env.
But i have an issue with notify option.
I have an apache conf:
class apache inherits apache::params {
package { 'apache':
name => "${apache::params::package}",
ensure => present
}
service { 'apache':
ensure => running,
name => $apache::params::service,
enable => true,
subscribe => Package['apache'],
}
}
and and php module conf:
define php::module(
$notify = $php::params::notify,
$package_prefix = $php::params::module_package_prefix
) {
package { "php-module-${name}":
ensure => present,
name => "${package_prefix}${name}",
notify => Service['apache'],
require => [Class['apache'], Package['php', 'php-dev']]
}
}
but when I launch puppet I have this error:
Error: Parameter notify failed on Php::Module[mcrypt]: No title provided and "apache" is not a valid resource reference
I don't understand why it said that apache service is not a valid resources ?
I think there might be 2 issues here:
1) Puppet doesn't like this line in php::module:
$notify = $php::params::notify,
Can you try to remove that or check what is in $php::params::notify? (I don't see you using it)
2) Did you have something like
include apache
in your site.pp? The class still needs to be declared before you can reference the contained resources.
Related
I'm migrating a from puppetmaster on Xenial (v3.8.5) to Bionic (v5.4.0) and have run into an issue. So far I've copied the node and modules files from the old server to the new and had a client connect. I keep getting the following error on the client and master:
Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Could not find template 'ntp/client_ntp.conf.erb' (file: /etc/puppet/code/environments/production/manifests/modules/ntp/manifests/init.pp, line: 17, column: 20) on node owain18.dimerocker.com
The template file exists at: /etc/puppet/code/environments/production/manifests/modules/ntp/templates/client_ntp.conf.erb
The contents of ntp/manifests/init.pp:
class ntp {
package { "ntp": }
file { "/etc/ntp.conf":
mode => "644",
content => template("ntp/client_ntp.conf.erb"),
notify => Service["ntp"],
require => Package["ntp"],
} # file
service { "ntp":
ensure => running,
enable => true,
require => Package["ntp"],
} # service
} # class ntp
(I removed some comments from the top of the file so the line number in the error doesn't match, but there's no code missing.)
Any pointers on how to fix this issue? Thanks for your help.
I need to write a single manifest as install-apache.pp that will install
apache2 package if it is Debian based system or
httpd package if it is RedHat based system
Below is the code; this works in CentOS but does not work in Ubuntu.
case $facts['os']['name'] {
'Debian': {
package { 'apache2':
ensure => installed,
}
service { 'apache2':
ensure => running,
}
}
'RedHat': {
package { 'httpd' :
ensure => installed,
}
service { 'httpd':
ensure => running,
}
}
}
So I made some changes as below, but am not sure why it is not working.
case $operatingsystem {
'Debian': {
package { 'apache2':
ensure => installed,
} ->
service { 'apache2':
ensure => running,
enable => true,
}
}
'RedHat': {
package { 'httpd' :
ensure => installed,
} ->
service { 'httpd':
ensure => running,
enable => true,
}
}
}
Command used to execute:
puppet apply install-apache.pp --logdest /root/output.log
The problem here is that you are making use of the fact $facts['os']['name'] which is assigned the specific operating system of the distribution and not the family of the distribution. That fact will be assigned Ubuntu on Ubuntu and not Debian. The fact needs to be fixed to $facts['os']['family'], which will be assigned Debian on Ubuntu.
You can also make use of selectors to improve this a bit more in addition to the fix. It is also recommended to construct a dependency of the service on the package in that manifest to ensure proper ordering. Refreshing would also be helpful.
With those fixes and improvements in mind, your final manifest would look like:
$web_service = $facts['os']['family'] ? {
'RedHat' => 'httpd',
'Debian' => 'apache2',
default => fail('Unsupported operating system.'),
}
package { $web_service:
ensure => installed,
}
~> service { $web_service:
ensure => running,
enable => true,
}
Trying to use puppets file_line to update /etc/environment
class system_variables {
include stdlib
file { '/etc/environment':
ensure => present
} ->
file_line { 'Add ENVIRONMENT_TYPE':
path => '/etc/environment',
line => 'ENVIRONMENT_TYPE="production"',
match => '^ENVIRONMENT_TYPE'
}
}
But keep getting error:
Error: /Stage[main]/System_variables/File_line[Add ENVIRONMENT_TYPE]: Could not evaluate: Invalid parameter encoding(:encoding)
I have tried googling but to no avail.
Edit:
Ive also tested it on the master server where it runs without errors.
The file encoding is the same on both servers, and checked locales on each server aswell.
I am having issues with puppet modules, and this modules should replace /etc/ssh/sshd_config file based on Redhat version. So the issue is, after applying the code, puppet deleted the file, instead of replacing it.
someone please suggest any wrong with my code.
here is the my puppet manifest file;
class os_vul_ssh {
case $::operatingsystemmajrelease {
'6':{$sshconfigfile = 'sshd_config.rhel6'}
'7':{$sshconfigfile = 'sshd_config.rhel7'}
}
package { "openssh-server":
ensure => installed,
}
service { 'sshd':
ensure => "running",
enable => true,
require => Package["openssh-server"],
}
file { "/etc/ssh/sshd_config":
owner => root,
group => root,
mode => '0644',
source => "puppet:///modules/os_vul/${::sshconfigfile}",
require => Package["openssh-server"],
notify => Service["sshd"],
}
}
file { "/etc/ssh/sshd_config":
ensure => file, <----- this is missing
owner => root,
group => root,
mode => '0644',
source => "puppet:///modules/os_vul/${::sshconfigfile}",
require => Package["openssh-server"],
notify => Service["sshd"],
}
Might be more going on here, but this is the first issue that jumps out at me.
By the way, you can cleanup your code with this:
file { "/etc/ssh/sshd_config":
ensure => file,
owner => root,
group => root,
mode => '0644',
source => "puppet:///modules/os_vul/sshd_config.rhel${::operatingsystemmajrelease}",
require => Package["openssh-server"],
notify => Service["sshd"],
}
and if you are using Facter 3 then consider changing your fact to:
$facts['operatingsystemmajrelease']
and note that your sshconfigfile is a local variable and should be included in your file resource as a local variable $sshconfigfile and not global $::sshconfigfile.
I'm migrating our old process of doing our linux configurations to be managed by puppet but I'm having issues trying to figure out how to do this. We add some custom scripts to the init.d folder on our systems to manage some processes, and then these need this command executed on them to launch on startup:
update-rc.d $file defaults
So what I'm doing with puppet is that I have all these scripts residing a directory, and I copy them over to init.d. I then want to call 'exec' on each of these files with the former command and use the file name as an argument. This is what I have so far:
#copy init files
file { '/etc/init.d/':
ensure => 'directory',
recurse => 'remote',
source => ["puppet:///files/init_files/"],
mode => 755,
notify => Exec[echo],
}
exec { "echo":
command => "update-rc.d $file defaults",
cwd => "/tmp", #directory to execute from
path => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:",
refreshonly => true
}
This will copy all the files and it calls exec when something is added/updated, but what I can't figure out is how to pass the name of the file as an argument into the exec command. It seems I'm really close but I just can't find anything to help with what I need to do. Is this the right way to try and achieve this?
Thanks.
Your probably not going to accomplish that if your using ensure => 'directory'. You will want to declare the file resource for each individual init script. And the exec isn't the way to go to enable a service. Use the service resource.
file { '/etc/init.d':
ensure => 'directory',
mode => '0755'
}
file { '/etc/init.d/init_script_1':
ensure => 'present',
owner => 'root',
group => 'root',
mode => '0755',
notify => Service['init_script_1']
}
file { '/etc/init.d/init_script_2':
ensure => 'present',
owner => 'root',
group => 'root',
mode => '0755',
notify => Service['init_script_2']
}
service { 'init_script_1':
ensure => running,
enable => true
}
service { 'init_script_2':
ensure => running,
enable => true
}
Hope this helps.