Class: RSpecSystem::Helpers::ForemanInstall

Inherits:
RSpecSystem::Helper
  • Object
show all
Defined in:
lib/rspec-system-foreman/helpers/foreman_install.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
# File 'lib/rspec-system-foreman/helpers/foreman_install.rb', line 7

def execute
  node = opts[:node]
  facts = node.facts

  if facts['osfamily'] == 'RedHat' && facts['operatingsystem'] != 'Fedora'
    log.info "Configuring EPEL"
    if facts['operatingsystemrelease'] =~ /^6\./
      shell :c => 'rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm', :n => node
    else
      shell :c => 'rpm -ivh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm', :n => node
    end
  end

  answers = {}
  shell :c => 'cat /usr/share/foreman-installer/foreman_installer/answers.yaml', :n => node do |r|
    answers = YAML.load(r.stdout)
  end
  # Merge user answers into defaults (can be booleans or hashes)
  if opts[:answers]
    opts[:answers].each do |k,v|
      k = k.to_s
      v = Hash[v.map {|k,v| [k.to_s, v] }] if v.is_a? Hash
      if (!v && answers[k]) || (v && !answers[k])  # invert override
        answers[k] = v
      elsif v.is_a?(Hash) && !answers[k].is_a?(Hash)  # override with options
        answers[k] = v
      elsif v.is_a?(Hash) && answers[k].is_a?(Hash)  # merge options
        answers[k].merge! v
      end
    end
  end

  log.info "Install answers file: #{answers.inspect}"
  shell :c => 'mkdir /etc/foreman-installer', :n => node
  file = Tempfile.new('answers')
  begin
    file.write(answers.to_yaml)
    file.close
    rcp :sp => file.path, :dp => '/etc/foreman-installer/answers.yaml', :d => node
  ensure
    file.unlink
  end

  # Run foreman-installer
  puppet_apply(:code => 'class { "foreman_installer": }', :n => node, :module_path => '/usr/share/foreman-installer')

  {}
end