I need to write a single manifest as install-apache.pp
that will install
apache2
package if it is Debian based system orhttpd
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 assignedUbuntu
on Ubuntu and notDebian
. The fact needs to be fixed to$facts['os']['family']
, which will be assignedDebian
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 thepackage
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: