CentOS Stream 9
Sponsored Link

Puppet : How to use [service Resource]2023/10/17

 

This is the examples for [service] resource.

[1] It manages the configuration to keep [httpd] is running.
[root@dlp ~]#
vi /etc/puppetlabs/code/environments/production/manifests/svc01.pp
service { 'httpd':
  name   => 'httpd',
  ensure => running,
}
[2] It manages the configuration to keep [httpd] is running.
However, if [httpd] is not installed, [httpd] can not start of course, so it manages the configuration to keep [httpd] is installed with [require] parameter like follows.
[root@dlp ~]#
vi /etc/puppetlabs/code/environments/production/manifests/pkg01.pp
package { 'httpd':
  provider => yum,
  ensure   => installed,
}

[root@dlp ~]#
vi /etc/puppetlabs/code/environments/production/manifests/svc01.pp
service { 'httpd':
  name    => 'httpd',
  ensure  => running,
  require => Package['httpd'],
}
[3] It manages the configuration to keep Nginx is not running. If running, it stops.
[root@dlp ~]#
vi /etc/puppetlabs/code/environments/production/manifests/svc02.pp
service { 'nginx':
  name   => 'nginx',
  ensure => stopped,
}
[4] It restarts [httpd] when the file [/etc/httpd/conf.d/security.conf] is updated.
[root@dlp ~]#
vi /etc/puppetlabs/code/environments/production/manifests/svc03.pp
file { '/etc/httpd/conf.d/security.conf':
  ensure => file,
  owner  => 'root',
  group  => 'root',
  mode   => '0644',
  source => 'puppet://dlp.srv.world/extra_files/security.conf',
  notify => Service['httpd'],
}

[root@dlp ~]#
vi /etc/puppetlabs/puppet/files/security.conf
ServerTokens Prod
ServerSignature On
TraceEnable Off
Matched Content