Ubuntu 22.04
Sponsored Link

Puppet : How to use [class Section]2023/10/12

 

It's possible to manage some resources by using [class] section like follows.

[1] It's an example to define and use [sample01] class.
root@dlp:~#
vi /etc/puppetlabs/code/environments/production/manifests/class.pp
class sample01 {
  file { '/home/testfile7.txt':
    ensure  => file,
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    content => 'This is the puppet test file.',
  }
  user { 'jammy':
    ensure     => present,
    home       => '/home/jammy',
    managehome => true,
    password   => '$6$0XTc2rjlxxxxxxxx',
    }
}
node 'node02.srv.world' { include 'sample01' }
[2] It's an example to use inheritance of a class. The [sample01] and [sample02] class are both applied to [node03.srv.world] by this manifest.
root@dlp:~#
vi /etc/puppetlabs/code/environments/production/manifests/class.pp
class sample01 {
  file { '/home/testfile7.txt':
    ensure  => file,
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    content => 'This is the puppet test file.',
  }
  user { 'jammy':
    ensure     => present,
    home       => '/home/jammy',
    managehome => true,
    password   => '$6$0XTc2rjlxxxxxxxx',
    }
}
class sample02 inherits sample01 {
  file { '/home/testfile8.txt':
    ensure  => file,
    owner   => 'root',
    group   => 'adm',
    content => 'test file #8',
  }
}
node 'node03.srv.world' { include 'sample02' }
Matched Content