CS-Notes/docs/_style/prism-master/examples/prism-puppet.html

152 lines
3.7 KiB
HTML
Raw Normal View History

2018-12-19 14:09:39 +08:00
<h2>Comments</h2>
<pre><code>#
# Foobar
/* Foo
bar */</code></pre>
<h2>Strings and interpolation</h2>
<pre><code>'foo \'bar\' baz'
"$foo \"bar\" ${baz}"
@(FOOBAR) # Unquoted heredoc string
Foo bar baz
FOOBAR
@("BARBAZ"/$L) # Quoted heredoc string
$foo bar ${baz}
|-BARBAZ</code></pre>
<h2>Regular expressions</h2>
<pre><code>if $host =~ /^www(\d+)\./ {}
$foo = /foo
bar # Extended regexes can include comments
baz/x</code></pre>
<h2>Variables</h2>
<pre><code>$foo
$::foobar
$foo::bar::baz</code></pre>
<h2>Functions</h2>
<pre><code>require apache
template('apache/vhost-default.conf.erb')
[1,20,3].filter |$value| { $value < 10 }</code></pre>
<h2>All-in-one example</h2>
<pre><code>file {'ntp.conf':
path => '/etc/ntp.conf',
ensure => file,
content => template('ntp/ntp.conf'),
owner => 'root',
mode => '0644',
}
package {'ntp':
ensure => installed,
before => File['ntp.conf'],
}
service {'ntpd':
ensure => running,
subscribe => File['ntp.conf'],
}
Package['ntp'] -> File['ntp.conf'] ~> Service['ntpd']
$package_list = ['ntp', 'apache2', 'vim-nox', 'wget']
$myhash = { key => { subkey => 'b' }}
include ntp
require ntp
class {'ntp':}
define apache::vhost ($port, $docroot, $servername = $title, $vhost_name = '*') {
include apache
include apache::params
$vhost_dir = $apache::params::vhost_dir
file { "${vhost_dir}/${servername}.conf":
content => template('apache/vhost-default.conf.erb'),
owner => 'www',
group => 'www',
mode => '644',
require => Package['httpd'],
notify => Service['httpd'],
}
}
apache::vhost {'homepages':
port => 8081,
docroot => '/var/www-testhost',
}
Apache::Vhost['homepages']
node 'www1.example.com' {
include common
include apache
include squid
}
node /^www\d+$/ {
include common
}
# comment
/* comment */
if $is_virtual {
warning( 'Tried to include class ntp on virtual machine; this node may be misclassified.' )
}
elsif $operatingsystem == 'Darwin' {
warning( 'This NTP module does not yet work on our Mac laptops.' )
else {
include ntp
}
if $hostname =~ /^www(\d+)\./ {
notify { "Welcome web server $1": }
}
case $operatingsystem {
'Solaris': { include role::solaris }
'RedHat', 'CentOS': { include role::redhat }
/^(Debian|Ubuntu)$/:{ include role::debian }
default: { include role::generic }
}
$rootgroup = $osfamily ? {
'Solaris' => 'wheel',
/(Darwin|FreeBSD)/ => 'wheel',
default => 'root',
}
User <| groups == 'admin' |>
Concat::Fragment <<| tag == "bacula-storage-dir-${bacula_director}" |>>
Exec <| title == 'update_migrations' |> {
environment => 'RUBYLIB=/usr/lib/ruby/site_ruby/1.8/',
}
@user {'deploy':
uid => 2004,
comment => 'Deployment User',
group => www-data,
groups => ["enterprise"],
tag => [deploy, web],
}
@@nagios_service { "check_zfs${hostname}":
use => 'generic-service',
host_name => "$fqdn",
check_command => 'check_nrpe_1arg!check_zfs',
service_description => "check_zfs${hostname}",
target => '/etc/nagios3/conf.d/nagios_service.cfg',
notify => Service[$nagios::params::nagios_service],
}</code></pre>
<h2>Known failures</h2>
<p>There are certain edge cases where Prism will fail.
There are always such cases in every regex-based syntax highlighter.
However, Prism dares to be open and honest about them.
If a failure is listed here, it doesnt mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
</p>
<h3>More than one level of nested braces inside interpolation</h3>
<pre><code>"Foobar ${foo({
bar => {baz => 42}
baz => 42
})} <- broken"</code></pre>