class Runpuppet::Config

Attributes

config_path[RW]
data[RW]

Public Class Methods

find_system_config() click to toggle source
# File lib/runpuppet/config.rb, line 16
def self.find_system_config
  home = File.expand_path('~')
  pathes = ["#{home}/.runpuppet.yml", '/etc/runpuppet.yml']
  pathes.each do |file|
    return Runpuppet::Config.new(file) if File.exist?(file)
  end
  puts "No runpuppet.yml found in #{pathes.join(' or ')}"
  exit
end
new(config_path) click to toggle source
# File lib/runpuppet/config.rb, line 5
def initialize(config_path)
  @config_path = config_path
  load_data
end

Public Instance Methods

command() click to toggle source
# File lib/runpuppet/config.rb, line 44
def command
  # "cd /etc/puppet/repo && git fetch && git checkout -f origin/@@branch@@ && puppet -v --debug --logdest console --modulepath /etc/puppet/repo/modules /etc/puppet/repo/manifests/site.pp"
  data['command']
end
default_branch() click to toggle source
# File lib/runpuppet/config.rb, line 57
def default_branch
  data['branch'] || 'master'
end
extract_auth_from_url!(url) click to toggle source
# File lib/runpuppet/config.rb, line 34
def extract_auth_from_url!(url)
  url.sub!(%r{//(.*?):(.*?)@}, '//')
  auth = [$1, $2].compact
  auth.empty? ? nil : auth
end
hostname() click to toggle source
# File lib/runpuppet/config.rb, line 76
def hostname
  Socket.gethostname
end
is_ec2?() click to toggle source
# File lib/runpuppet/config.rb, line 86
def is_ec2?
  read_shell('arp -n -i eth0') =~ /fe:ff:ff:ff:ff/
end
load_data() click to toggle source
# File lib/runpuppet/config.rb, line 11
def load_data
  raise "No runpuppet.yml found in #{config_path}" unless File.exist?(config_path)
  @data = YAML.load(File.read(config_path))
end
local_ip() click to toggle source
# File lib/runpuppet/config.rb, line 61
def local_ip
  if is_ec2?
    require 'facter'
    require 'facter/ec2'
    ip = Facter.value("ec2_public_ipv4")
  elsif data['local_ip_interface']
    parse_local_ip_from_interface
  else
    ifconfig = read_shell('ifconfig')
    data['local_ip'] or
      ifconfig[/192.168.\d+.\d+/] or
      ifconfig[/10.10.\d+.\d+/]
  end
end
lock_file() click to toggle source
# File lib/runpuppet/config.rb, line 40
def lock_file
  data['lock_file'] || '/tmp/runpuppet.lock'
end
parse_local_ip_from_interface() click to toggle source
# File lib/runpuppet/config.rb, line 80
def parse_local_ip_from_interface
  cmd = "ip addr list #{data['local_ip_interface']}"
  read_shell(cmd).match(/inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?/)
  return $1
end
puppet_controller_auth() click to toggle source
# File lib/runpuppet/config.rb, line 30
def puppet_controller_auth
  extract_auth_from_url!(puppet_controller_url)
end
puppet_controller_url() click to toggle source
# File lib/runpuppet/config.rb, line 26
def puppet_controller_url
  data['puppet_controller_url'].sub(%r{/$},'')
end
read_shell(cmd) click to toggle source
# File lib/runpuppet/config.rb, line 90
def read_shell(cmd)
  %x(#{cmd})
end
verbose_command() click to toggle source
# File lib/runpuppet/config.rb, line 49
def verbose_command
  unless data['verbose_command']
    puts "No verbose_command param in #{config_path} found! using normal command."
    return self.command
  end
  data['verbose_command']
end