This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <modulepath>/rcsrepo/spec/unit/puppet/provider/rcsrepo/git_spec.rb | |
require 'puppet' | |
require 'fileutils' | |
require 'puppet/type/rcsrepo' | |
RSpec.configure { |config| config.mock_with :mocha } | |
describe 'The git provider for the rcsrepo type' do | |
let(:test_dir) { '/path/to/repo' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Puppet::Type.type(:rcsrepo).provide(:git) do | |
desc "A Git provider for the Rcsrepo type" | |
confine :has_git => true | |
commands :git => 'git' | |
def exists? | |
File.directory?("#{resource[:path]}/.git") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'pathname' | |
Puppet::Type.newtype(:rcsrepo) do | |
desc "A Puppet type to model a Version Control Repository" | |
ensurable | |
newparam(:path, :namevar => true) do | |
desc "Path to our version control repository" | |
validate do |value| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <modulepath>/rcsrpo/spec/unit/puppet/type/rcsrepo_spec.rb | |
require 'puppet' | |
require 'puppet/type/rcsrepo' | |
describe Puppet::Type.type(:rcsrepo) do | |
subject { Puppet::Type.type(:rcsrepo).new(:path => '/foo') } | |
it 'should accept ensure' do | |
subject[:ensure] = :present | |
subject[:ensure].should == :present |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <modulepath>/custom_functions/lib/puppet/parser/functions/longest.rb | |
Puppet::Parser::Functions.newfunction(:longest, :type => :rvalue, :doc => "Longest Function") do |args| | |
raise Puppet::Error, "#longest: accepts only one argument, you passed #{args.length}" if args.length != 1 | |
raise Puppet::Error, "#longest: accepts a single Array, you passed: #{args[0].class}" if args[0].class != Array | |
@longest = '' | |
args[0].each do |item| | |
@longest = item if item.length > @longest.length | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <modulepath>/custom_functions/lib/puppet/parser/functions/longest.rb | |
Puppet::Parser::Functions.newfunction(:longest, :type => :rvalue, :doc => "Longest Function") do |args| | |
raise Puppet::Error, "#longest: accepts only one argument, you passed #{args.length}" if args.length != 1 | |
raise Puppet::Error, "#longest: accepts a single Array, you passed: #{args[0].class}" if args[0].class != Array | |
@longest = '' | |
args[0].each do |item| | |
@longest = item if item.length > @longest.length | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <modulepath>/custom_functions/spec/unit/puppet/parser/functions/extract_spec.rb | |
require 'puppet' | |
require 'rspec-puppet' | |
describe Puppet::Parser::Functions.function(:extract) do | |
let :scope do | |
PuppetlabsSpec::PuppetInternals.scope | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Iterate through list of packages | |
IO.popen('repoquery --installed -a --qf \'%{name} %{version}\'').readlines.map(&:chomp).each do |line| | |
name, version = line.split | |
Facter.add("yum_#{name}_version") do | |
setcode do | |
version | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <modulepath>/custom_functions/lib/puppet/parser/functions/extract.rb | |
require 'yaml' | |
Puppet::Parser::Functions.newfunction(:extract, :type => :rvalue, :doc => "YAML Extract") do |args| | |
raise Puppet::Error, "#extract: accepts only two arguments, you passed #{args.length}" if args.length != 2 | |
file = args[0] | |
field = args[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
require 'pry' | |
passwd_file = File.readlines('/etc/passwd') | |
@yaml_hash = {} | |
passwd_file.each do |line| | |
line_array = line.split(':') | |
username = line_array[0] |