Skip to content

Instantly share code, notes, and snippets.

View trevor-vaughan's full-sized avatar

Trevor Vaughan trevor-vaughan

View GitHub Profile
@trevor-vaughan
trevor-vaughan / demo_classvars.rb
Last active December 25, 2015 23:49
Material for the walkthrough of storing Puppet provider metadata for single instance application hosted at https://www.onyxpoint.com/storing-puppet-provider-metadata-for-single-instance-application.
@@demo_classvars = {
# This provider is set up to only target *one* file. To target
# multiple files, you'll need to do some creative adjustment to
# how your provider works.
:target_file => "/tmp/demo_provider.txt",
# The original content of the target file (if any).
:old_content => "",
# The new content of the target file.
@trevor-vaughan
trevor-vaughan / redhat_rename
Created January 9, 2015 20:03
Rename RPMs downloaded from Red Hat
ruby -r fileutils -e 'Dir.glob("*rpm?*").each do |file| file =~ /(.*)rpm\?.*/; FileUtils.mv(file,"#{$1}rpm") end'
@trevor-vaughan
trevor-vaughan / findunsigned
Created January 9, 2015 20:05
Find Unsigned Packages in a RPM repository
for file in `find . -name "*.rpm"`; do rpm -qip $file 2>/dev/null | grep -qe "Signature.*(none)" && echo $file; done
@trevor-vaughan
trevor-vaughan / spec_helper_snippet.rb
Created April 18, 2015 01:50
spec_helper.rb snippet for custom environments in rspec-puppet tests.
require 'puppetlabs_spec_helper/module_spec_helper'
def set_environment(environment = :production)
RSpec.configure { |config| config.default_facts['environment'] = environment.to_s }
end
RSpec.configure do |config|
config.before(:each) do
if defined?(environment)
set_environment(environment)
@trevor-vaughan
trevor-vaughan / init_spec.rb
Last active August 29, 2015 14:19
using custom environments in rspec-puppet
require 'spec_helper'
describe 'my_class' do
it { should compile.with_all_deps }
context 'with defaults for all parameters in the :development environment' do
# The magic happens here!
let(:environment){:development}
it { should compile.with_all_deps }
it { should contain_class('my_class') }
@trevor-vaughan
trevor-vaughan / convert_rst_tables.rb
Last active August 29, 2015 14:27
A script to convert RestructuredText Tables to list-tables
#!/usr/bin/ruby
# Test your changes using rst2pdf
require 'fileutils'
input = ARGV[0]
tmpfile = %(#{input}.tmp)
File.exist?(input) || fail("'#{input}' is not a valid filename")
@trevor-vaughan
trevor-vaughan / grub2_pbkdf2.rb
Created February 3, 2016 21:02
Generate and validate GRUB2 compatible Password Hashes in Ruby
#!/usr/bin/env ruby
require 'openssl'
def pack_salt(salt)
return salt.scan(/../).map{|x| x.hex }.pack('c*')
end
def unpack_salt(salt)
return salt.unpack('H*').first.upcase
@trevor-vaughan
trevor-vaughan / set_environment
Last active May 24, 2016 20:40
Set your Puppet Environment from Hiera
#!/usr/bin/env ruby
require 'yaml'
# The location of the environment data file
# The format of this file should be as follows:
# <regex/hostname> : <environment>
#
# <regex/hostname>: May be either a regular expression or a simple string that
# matches against the FQDN of the system.
@trevor-vaughan
trevor-vaughan / tagpush.rb
Created September 8, 2016 21:26
Push updated versions of all the Puppet modules
#!/usr/bin/ruby
require 'json'
github_base = 'git@github.com:simp/'
tmp_repo = 'fubarness'
failed_repos = []
Dir.glob('*').each do |dir|