Skip to content

Instantly share code, notes, and snippets.

@maxlinc
maxlinc / spec_helper.rb
Created August 29, 2013 19:57
rspec puppet debugging
RSpec.configure do |conf|
conf.module_path = File.join(fixture_path, 'modules')
conf.manifest_dir = File.join(fixture_path, 'manifests')
conf.hiera_config = File.join(fixture_path, 'hiera.yaml')
end
# Not sure this works for all types of https://github.com/rodjek/rspec-puppet tests. I think it works with host tests
if ENV['PUPPET_DEBUG']
Puppet::Util::Log.level = :debug
Puppet::Util::Log.newdestination(:console)
@maxlinc
maxlinc / use-go
Last active December 20, 2015 02:39
use-go ci-addon for cloudbees
#!/bin/bash
if [[ -z $GOLANG_VERSION ]]; then
GOLANG_VERSION=1.1.1
echo "No version provided for go, will use the last one: $GOLANG_VERSION" 1>&2
fi
set -e
ARCH=`uname -m`
# -*- encoding : utf-8 -*-
module Puppet::Parser::Functions
newfunction(:has_role, :type => :rvalue) do |role|
has_role?(role)
end
end
def has_role?(role)
pool = lookupvar "#{role.first}_pool"
if pool
@maxlinc
maxlinc / env_schema.yaml
Created June 28, 2013 14:38
Kwalify (environment)
type: map
mapping:
redis_password:
type: str
required: yes
# Uncomment the next line to require redis passwords to be encrypted
# pattern: /ENC[.*]/
toggles:
type: map
required: yes
@maxlinc
maxlinc / Vagrantfile
Created June 28, 2013 03:10
Fast acceptance test runner
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.synced_folder "..", "/etc/puppet"
config.vm.provision :shell, :inline => "puppet apply --modulepath '/etc/puppet/modules:/etc/puppet/my_modules/' #{ENV['MANIFEST_FILE']} --detailed-exitcodes || [ $? -eq 2 ]"
config.vm.box = "ubuntu_precise64"
config.vm.hostname = "module-test.example.com"
config.vm.box_url = "http://f.willianfernandes.com.br/vagrant-boxes/UbuntuServer12.04amd64.box"
@maxlinc
maxlinc / my_frontend.pp
Created June 27, 2013 16:29
Kwalify (code)
class apps::my_frontend($ensure = 'present', $port = 8080) {
$args = get_scope_args()
$schema = {
'type' => 'map',
'mapping' => {
'ensure' => {
'type' => 'str',
'enum' => ['present', 'absent'],
},
'port' => {
@maxlinc
maxlinc / whitespace.rake
Created June 27, 2013 16:09
Whitespace
# -*- encoding : utf-8 -*-
class WhitespaceCheck < Struct.new(:pattern, :message)
def lines
@lines ||= []
end
def check(line, number)
lines << number if line =~ pattern
@maxlinc
maxlinc / lint.rake
Created June 27, 2013 16:08
Puppet Linting
require 'puppet-lint'
PuppetLint.configuration.log_format = '%{path}:%{linenumber} - %{KIND}: %{message}'
PuppetLint.configuration.send('disable_80chars')
task :lint do
linter = PuppetLint.new
PuppetLint.configuration.send("disable_documentation")
Dir['manifests/**/*.pp'].each do |pp|
linter.file = pp
linter.run
@maxlinc
maxlinc / validate_syntax.rake
Created June 27, 2013 16:07
Syntax Checking
desc 'Validates the syntax of the puppet manifest files'
task :validate do
puts `puppet parser validate #{Dir['**/*.pp'].join(' ')}`
fail unless $?.to_i == 0
end
@maxlinc
maxlinc / Vagrantfile
Created June 21, 2013 19:33
Record facts for any host, reuse within rspec-puppet
...
config.vm.provision :shell, :inline => "facter --yaml > /vagrant/fixtures/facts/$HOSTNAME.yaml"
...