| 1 | <h2>Comments</h2> |
| 2 | <pre><code># |
| 3 | # Foobar |
| 4 | /* Foo |
| 5 | bar */</code></pre> |
| 6 | |
| 7 | <h2>Strings and interpolation</h2> |
| 8 | <pre><code>'foo \'bar\' baz' |
| 9 | "$foo \"bar\" ${baz}" |
| 10 | |
| 11 | @(FOOBAR) # Unquoted heredoc string |
| 12 | Foo bar baz |
| 13 | FOOBAR |
| 14 | |
| 15 | @("BARBAZ"/$L) # Quoted heredoc string |
| 16 | $foo bar ${baz} |
| 17 | |-BARBAZ</code></pre> |
| 18 | |
| 19 | <h2>Regular expressions</h2> |
| 20 | <pre><code>if $host =~ /^www(\d+)\./ {} |
| 21 | $foo = /foo |
| 22 | bar # Extended regexes can include comments |
| 23 | baz/x</code></pre> |
| 24 | |
| 25 | <h2>Variables</h2> |
| 26 | <pre><code>$foo |
| 27 | $::foobar |
| 28 | $foo::bar::baz</code></pre> |
| 29 | |
| 30 | <h2>Functions</h2> |
| 31 | <pre><code>require apache |
| 32 | template('apache/vhost-default.conf.erb') |
| 33 | [1,20,3].filter |$value| { $value < 10 }</code></pre> |
| 34 | |
| 35 | <h2>All-in-one example</h2> |
| 36 | <pre><code>file {'ntp.conf': |
| 37 | path => '/etc/ntp.conf', |
| 38 | ensure => file, |
| 39 | content => template('ntp/ntp.conf'), |
| 40 | owner => 'root', |
| 41 | mode => '0644', |
| 42 | } |
| 43 | package {'ntp': |
| 44 | ensure => installed, |
| 45 | before => File['ntp.conf'], |
| 46 | } |
| 47 | service {'ntpd': |
| 48 | ensure => running, |
| 49 | subscribe => File['ntp.conf'], |
| 50 | } |
| 51 | Package['ntp'] -> File['ntp.conf'] ~> Service['ntpd'] |
| 52 | |
| 53 | $package_list = ['ntp', 'apache2', 'vim-nox', 'wget'] |
| 54 | $myhash = { key => { subkey => 'b' }} |
| 55 | |
| 56 | include ntp |
| 57 | require ntp |
| 58 | class {'ntp':} |
| 59 | |
| 60 | define apache::vhost ($port, $docroot, $servername = $title, $vhost_name = '*') { |
| 61 | include apache |
| 62 | include apache::params |
| 63 | $vhost_dir = $apache::params::vhost_dir |
| 64 | file { "${vhost_dir}/${servername}.conf": |
| 65 | content => template('apache/vhost-default.conf.erb'), |
| 66 | owner => 'www', |
| 67 | group => 'www', |
| 68 | mode => '644', |
| 69 | require => Package['httpd'], |
| 70 | notify => Service['httpd'], |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | apache::vhost {'homepages': |
| 75 | port => 8081, |
| 76 | docroot => '/var/www-testhost', |
| 77 | } |
| 78 | Apache::Vhost['homepages'] |
| 79 | |
| 80 | node 'www1.example.com' { |
| 81 | include common |
| 82 | include apache |
| 83 | include squid |
| 84 | } |
| 85 | node /^www\d+$/ { |
| 86 | include common |
| 87 | } |
| 88 | |
| 89 | # comment |
| 90 | /* comment */ |
| 91 | |
| 92 | if $is_virtual { |
| 93 | warning( 'Tried to include class ntp on virtual machine; this node may be misclassified.' ) |
| 94 | } |
| 95 | elsif $operatingsystem == 'Darwin' { |
| 96 | warning( 'This NTP module does not yet work on our Mac laptops.' ) |
| 97 | else { |
| 98 | include ntp |
| 99 | } |
| 100 | |
| 101 | if $hostname =~ /^www(\d+)\./ { |
| 102 | notify { "Welcome web server $1": } |
| 103 | } |
| 104 | |
| 105 | case $operatingsystem { |
| 106 | 'Solaris': { include role::solaris } |
| 107 | 'RedHat', 'CentOS': { include role::redhat } |
| 108 | /^(Debian|Ubuntu)$/:{ include role::debian } |
| 109 | default: { include role::generic } |
| 110 | } |
| 111 | $rootgroup = $osfamily ? { |
| 112 | 'Solaris' => 'wheel', |
| 113 | /(Darwin|FreeBSD)/ => 'wheel', |
| 114 | default => 'root', |
| 115 | } |
| 116 | |
| 117 | User <| groups == 'admin' |> |
| 118 | Concat::Fragment <<| tag == "bacula-storage-dir-${bacula_director}" |>> |
| 119 | |
| 120 | Exec <| title == 'update_migrations' |> { |
| 121 | environment => 'RUBYLIB=/usr/lib/ruby/site_ruby/1.8/', |
| 122 | } |
| 123 | |
| 124 | @user {'deploy': |
| 125 | uid => 2004, |
| 126 | comment => 'Deployment User', |
| 127 | group => www-data, |
| 128 | groups => ["enterprise"], |
| 129 | tag => [deploy, web], |
| 130 | } |
| 131 | |
| 132 | @@nagios_service { "check_zfs${hostname}": |
| 133 | use => 'generic-service', |
| 134 | host_name => "$fqdn", |
| 135 | check_command => 'check_nrpe_1arg!check_zfs', |
| 136 | service_description => "check_zfs${hostname}", |
| 137 | target => '/etc/nagios3/conf.d/nagios_service.cfg', |
| 138 | notify => Service[$nagios::params::nagios_service], |
| 139 | }</code></pre> |