Puppet : How to use [service Resource]2024/07/25 |
This is the examples for [service] resource. |
|
[1] | It manages the configuration to keep [apache2] is running. |
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/svc01.pp service { 'apache2': name => 'apache2', ensure => running, } |
[2] | It manages the configuration to keep [apache2] is running. However, if [apache2] is not installed, [apache2] can not start of course, so it manages the configuration to keep [apache2] is installed with [require] parameter like follows. |
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/pkg01.pp package { 'apache2': provider => apt, ensure => installed, }
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/svc01.pp service { 'apache2': name => 'apache2', ensure => running, require => Package['apache2'], } |
[3] | It manages the configuration to keep Nginx is not running. If running, it stops. |
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/svc02.pp service { 'nginx': name => 'nginx', ensure => stopped, } |
[4] | It restarts [apache2] when the file [/etc/apache2/conf-available/security.conf] is updated. |
root@dlp:~#
vi /etc/puppet/code/environments/production/manifests/svc03.pp file { '/etc/apache2/conf-available/security.conf': ensure => file, owner => 'root', group => 'root', mode => '0644', source => 'puppet://dlp.srv.world/extra_files/security.conf', notify => Service['apache2'], }
root@dlp:~#
vi /etc/puppet/files/security.conf ServerTokens Prod ServerSignature On TraceEnable Off |
Sponsored Link |