Class: RSpecSystem::Helpers::ForemanInstallerInstall

Inherits:
RSpecSystem::Helper
  • Object
show all
Defined in:
lib/rspec-system-foreman/helpers/foreman_installer_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
55
56
57
58
59
60
61
62
63
# File 'lib/rspec-system-foreman/helpers/foreman_installer_install.rb', line 7

def execute
  node = opts[:node]
  puppet_install opts

  facts = node.facts

  # Install the installer and optionally the repo
  if opts[:installer_source]
    log.info "Copying custom foreman-installer source checkout to /usr/share/foreman-installer"
    rcp :sp => opts[:installer_source], :dp => '/usr/share/foreman-installer'
  else
    if facts['osfamily'] == 'RedHat'
      if opts[:custom_repo]
        log.info "Installing custom yum repo from #{opts[:custom_repo]}"
        file = Tempfile.new('foreman.repo')
        begin
          file.write(<<EOS)
[foreman]
name=Foreman custom repo
baseurl=#{opts[:custom_repo]}
gpgcheck=0
EOS
          file.close
          rcp :sp => file.path, :dp => '/etc/yum.repos.d/foreman.repo', :d => node
        ensure
          file.unlink
        end
      else
        repo = case facts['operatingsystem']
        when 'Fedora'
          "f#{facts['operatingsystemrelease']}"
        else
          "el#{facts['operatingsystemrelease'][0]}"
        end
        opts[:release_url] ||= "http://yum.theforeman.org/#{opts[:repo] || 'releases/latest'}/#{repo}/#{facts['architecture']}/foreman-release.rpm"
        log.info "Installing release repo #{opts[:release_url]}"
        shell :c => "rpm -ivh #{opts[:release_url]}", :n => node
      end
      shell :c => 'yum -y install foreman-installer', :n => node
    elsif facts['osfamily'] == 'Debian'
      sources = "deb http://deb.theforeman.org/ #{facts['lsbdistcodename']} #{opts[:repo] || 'stable'}"
      log.info "Configuring sources: #{sources}"
      file = Tempfile.new('foreman.sources')
      begin
        file.write("#{sources}\n")
        file.close
        rcp :sp => file.path, :dp => '/etc/apt/sources.list.d/foreman.list', :d => node
      ensure
        file.unlink
      end
      shell :c => 'wget -q http://deb.theforeman.org/foreman.asc -O- | apt-key add -', :n => node
      shell :c => 'apt-get update && apt-get -y install foreman-installer', :n => node
    end
  end

  {}
end