Skip to content

Instantly share code, notes, and snippets.

View binford2k's full-sized avatar

Ben Ford binford2k

View GitHub Profile
@binford2k
binford2k / example.pp
Last active September 25, 2017 02:48
# the format of a puppet resource
resource_type { 'resource title':
ensure => 'the state I want the resource to exist in',
property1 => value,
property2 => value,
property3 => value,
}
# a silly example that might go on a job listing
---
:backends:
- yaml
:yaml:
:datadir: /etc/puppetlabs/code/hieradata
:hierarchy:
- "%{::trusted.certname}"
- "%{environment}"
file { '/etc/motd':
ensure => file,
content => 'What I expect in the motd',
}
concat { '/etc/motd':
ensure => present,
}
concat::fragment { 'motd header':
target => '/etc/motd',
order => '01',
Puppet::Parser::Functions.newfunction(:local_scope,
:type => :rvalue,
:doc => <<-'EOS'
Generates the local scope as a hash. This allows you to use epp functions more
or less like erb templates by passing local scope as the parameters argument.
e.g., `content => epp('mymodname/template.epp', local_scope() )`
EOS
) do |args|
scope = self.to_hash
scope.reject! { |key,val| scope['facts'].include? key }
# this blows up with Error while evaluating a Resource Statement, Could not find stage last specified by Class[Test]
class {'test':
stage => 'last',
msg => 'boo',
}
stage { 'last': }
Stage['main'] -> Stage['last']
# this blows up with Error while evaluating a Resource Statement, Could not find stage last specified by Class[Test]
class {'test':
stage => 'last',
msg => 'boo',
}
stage { 'last': }
Stage['main'] -> Stage['last']
# Press the 'show relationships' button
# to see how these classes relate to one another
class outside {
include floater # this class is uncontained, so it will "float" outside the graph
contain contained # this class is contained, so it will be enforced within the parent class
require required # this class is required, so all we know is that it will be enforced before the parent class
}
class floater {
file { '/tmp/foo':
$data = [1,2,3,3,3,8,5,4,2,2,]
$dupes = $data.reduce |$memo, $value| {
if count($data, $value) > 1 {
[$memo, $value]
}
else {
[$memo]
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
['192.168.1.24','192.168.1.25'].each |$ipaddress| {
firewall_rule { "Allow HTTP access to ${ipaddress}":
source_ip = $ipaddress,
destination_port = 80,
protocol = 'tcp',
}
}