Skip to content

Instantly share code, notes, and snippets.

Test with External Function

When

You want to test a resource definition (class, defined type) that uses a function provided by a third-party module your module depends upon. It's supposed that you're implementing your tests with rspec-puppet.

How

@antaflos
antaflos / haproxy.cfg
Last active August 29, 2015 14:06 — forked from rnewson/haproxy.cfg
# Bind SSL port with PFS-enabling cipher suite
bind :443 ssl crt path_to_certificate no-tls-tickets ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-RSA-RC4-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES128-SHA:AES256-SHA256:AES256-SHA:RC4-SHA
# Distinguish between secure and insecure requests
acl secure dst_port eq 443
# Mark all cookies as secure if sent over SSL
rsprep ^Set-Cookie:\ (.*) Set-Cookie:\ \1;\ Secure if secure
# Add the HSTS header with a 1 year max-age
@antaflos
antaflos / addUser.sh
Last active August 29, 2015 14:08 — forked from lemonlatte/addUser.sh
#!/bin/sh
dn='dc=math,dc=nccu,dc=edu,dc=tw'
username='jim.yeh'
uid='jim.yeh'
gid='student'
cat << EOF > user_example.ldif
dn: cn=$username,ou=users,ou=login,$dn
#!/bin/bash
# Autostart Libvirt VM's created with Foreman
# /usr/share/foreman/config/hooks/host/managed/create/10_autostart_libvirt.sh
# Source: http://www.uberobert.com/autostart-libvirt-vms-in-foreman/
. $(dirname $0)/hook_functions.sh
username='admin'
password='changeme'
@antaflos
antaflos / configuration
Created September 30, 2015 17:20 — forked from saleeema/configuration
Logstash grok multiline; Java stack trace
input {
file {
path => "/root/mult.log"
start_position => "beginning"
sincedb_path => "/dev/null"
codec => multiline{
pattern => "^ -%{SPACE}%{TIMESTAMP_ISO8601}"
negate => true
@antaflos
antaflos / gist:dc4910058eb316029036
Created October 27, 2015 21:36
spec test error when using :undef
Failure/Error: let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-base', 'content').split("\n") }
Puppet::Error:
Could not parse for environment production: Syntax error at ':'; expected '}' at line 4 on node foo.example.com
# ./vendor/bundle/ruby/2.1.0/gems/puppet-3.7.5/lib/puppet/parser/parser_support.rb:157:in `on_error'
# ./vendor/bundle/ruby/2.1.0/gems/puppet-3.7.5/lib/puppet/parser/lexer.rb:501:in `scan'
# ./vendor/bundle/ruby/2.1.0/gems/puppet-3.7.5/lib/puppet/parser/parser_support.rb:168:in `parse'
# ./vendor/bundle/ruby/2.1.0/gems/puppet-3.7.5/lib/puppet/node/environment.rb:545:in `perform_initial_import'
# ./vendor/bundle/ruby/2.1.0/gems/puppet-3.7.5/lib/puppet/node/environment.rb:276:in `known_resource_types'
# ./vendor/bundle/ruby/2.1.0/gems/puppet-3.7.5/lib/puppet/resource/type_collection_helper.rb:5:in `known_resource_types'
# ./vendor/bundle/ruby/2.1.0/gems/puppet-3.7.5/lib/puppet/parser/compiler.rb:558:in `block in initvars'
@antaflos
antaflos / jenkins_haproxy_config.cfg
Created February 8, 2016 22:21 — forked from xelwarto/jenkins_haproxy_config.cfg
Jenkins CI haproxy configuration example
global
chroot /var/lib/haproxy
crt-base /etc/pki/tls/certs
daemon
group haproxy
log 127.0.0.1 local0
maxconn 2000
pidfile /var/run/haproxy.pid
stats socket /var/lib/haproxy/stats
tune.ssl.default-dh-param 2048
@antaflos
antaflos / erb-render.rb
Created October 12, 2016 01:40 — forked from jasonlai/erb-render.rb
Utility Ruby script to render ERB templates, loading a JSON file as source for instance variables (useful when you need to debug Puppet templates)
#!/usr/bin/env ruby
require 'erb'
require 'json'
require 'optparse'
require 'ostruct'
class ERBContext
def initialize(hash)
raise ArgumentError, 'hash must be a Hash object' unless hash.is_a?(::Hash)
@antaflos
antaflos / haproxy.cfg
Created March 17, 2017 14:22
Reverse proxy Puppet frontend with HAProxy
# This file managed by Puppet
global
chroot /var/lib/haproxy
daemon
group haproxy
log 127.0.0.1 local1 info
log-send-hostname
maxconn 4096
stats socket /var/lib/haproxy/admin.sock mode 660 level admin
stats socket /var/lib/haproxy/user.sock mode 666 level user
Puppet::Functions.create_function(:file_lookup_key) do
dispatch :file_lookup_key do
param 'String[1]', :key
param 'Hash[String[1],Any]', :options
param 'Puppet::LookupContext', :context
end
def file_lookup_key(key, options, context)
# Set interpolate = true by default and override it with the value of
# options['interpolate'], if set.