Skip to content

Latest commit

 

History

History
56 lines (45 loc) · 1.23 KB

File metadata and controls

56 lines (45 loc) · 1.23 KB

Defined Types

← Back to Language Reference


Defined types are like reusable resource templates. Unlike classes (which can only be declared once), defined types can be instantiated multiple times with different parameters:

# modules/vhost/manifests/init.pp
define vhost (
  String  $docroot,
  Integer $port      = 80,
  String  $server_name = $title,
  Boolean $ssl       = false,
) {
  file { "/etc/httpd/conf.d/${title}.conf":
    ensure  => file,
    content => epp('vhost/vhost.conf.epp', {
      'server_name' => $server_name,
      'docroot'     => $docroot,
      'port'        => $port,
      'ssl'         => $ssl,
    }),
    notify  => Service['httpd'],
  }

  file { $docroot:
    ensure => directory,
    owner  => 'apache',
    group  => 'apache',
  }
}

Using it:

vhost { 'blog':
  docroot     => '/var/www/blog',
  server_name => 'blog.example.com',
}

vhost { 'api':
  docroot     => '/var/www/api',
  server_name => 'api.example.com',
  port        => 8080,
  ssl         => true,
}

← Back to Language Reference

This document was created with the assistance of AI (Grok, xAI). All technical content has been reviewed and verified by human contributors.