Class: Puppetize::Controler

Inherits:
Object
  • Object
show all
Defined in:
lib/puppetize/puppetize.rb

Instance Method Summary collapse

Constructor Details

#initializeControler

Returns a new instance of Controler.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/puppetize/puppetize.rb', line 6

def initialize

  # Check distribution dependency
  puts "\nSorry, Distribution not supported, only redhat based at the moment \n\n" unless File.exist?('/etc/redhat-release') 

  # Create config dir if it doesn't exists:
  @config_dir = File.join(File.expand_path('~'),'.puppetize')
  @module_dir = File.join(File.expand_path('~'),'puppetize-module')
  @rpm_db = File.join(@config_dir,'rpmlist.db')
  FileUtils.mkdir @config_dir if Dir.glob(@config_dir).empty?

end

Instance Method Details

#buildObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/puppetize/puppetize.rb', line 26

def build

  # Verify necessary commands are installed:
  #

  commands = ['puppet','git']

  commands.each do |command|

    begin

      test = ENV['PATH'].split(':').map do |folder| 
        File.exists?(File.join(folder,command)) 
      end

      if ! test.include? true 
        puts "ERROR - #{command} is not installed or not available on default path"
        exit -1
      end

    rescue => e

      STDERR.puts "ERROR - #{e}"
      exit -1

    end

  end

  # Generate a standard empty module

  cmd "puppet module generate puppetize-module"
  

  #################################
  # Generate the Package resources:
 
  rpm_list = cmd("rpm -qa").split("\n")
  init_rpm_list = File.read(@rpm_db).split("\n")
  puppet_rpm_list = rpm_list - init_rpm_list 

  packagelist = []

  puppet_rpm_list.each do |rpm|
    name = cmd("rpm --query --qf %{NAME} #{rpm}")
    version = cmd("rpm --query --qf %{VERSION} #{rpm}")
    release = cmd("rpm --query --qf %{RELEASE} #{rpm}")
    packagelist << [name,version,release]
  end

  # Generate install.pp based on ERB template
  template = File.join(File.dirname(__FILE__), '..', '..', 'tpl', 'install.pp.erb')
  renderer = ERB.new(File.read(template))
  output = renderer.result(binding)
  File.open(File.join(@module_dir,'manifests','install.pp'),'w') {|f| f.write(output)}

  ######################################
  # Generate the configuration resources
  
end

#initObject



19
20
21
22
23
24
# File 'lib/puppetize/puppetize.rb', line 19

def init

  rpm_list = cmd "rpm -qa"
  File.open(@rpm_db, 'w') {|f| f.write(rpm_list) }
  
end

#resetObject



87
88
89
90
91
# File 'lib/puppetize/puppetize.rb', line 87

def reset

  puts "reset"

end