module Runpuppet class Config attr_accessor :config_path attr_accessor :data def initialize(config_path) @config_path = config_path load_data end def load_data raise "No runpuppet.yml found in #{config_path}" unless File.exist?(config_path) @data = YAML.load(File.read(config_path)) end 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 def puppet_controller_url data['puppet_controller_url'].sub(%r{/$},'') end def puppet_controller_auth extract_auth_from_url!(puppet_controller_url) end def extract_auth_from_url!(url) url.sub!(%r{//(.*?):(.*?)@}, '//') auth = [$1, $2].compact auth.empty? ? nil : auth end def lock_file data['lock_file'] || '/tmp/runpuppet.lock' end 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 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 def default_branch data['branch'] || 'master' end 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 def hostname Socket.gethostname end 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 def is_ec2? read_shell('arp -n -i eth0') =~ /fe:ff:ff:ff:ff/ end def read_shell(cmd) %x(#{cmd}) end end end