Module: Beaker::PuppetInstallHelper

Defined in:
lib/beaker/puppet_install_helper.rb

Instance Method Summary collapse

Instance Method Details

#find_agent_shaObject



112
113
114
# File 'lib/beaker/puppet_install_helper.rb', line 112

def find_agent_sha
  ENV['BEAKER_PUPPET_AGENT_SHA'] || ENV['PUPPET_AGENT_SHA']
end

#find_install_typeObject



103
104
105
106
107
108
109
110
# File 'lib/beaker/puppet_install_helper.rb', line 103

def find_install_type
  # XXX Just use default.is_pe? when PUPPET_INSTALL_TYPE=foss is removed.
  ENV['PUPPET_INSTALL_TYPE'] || if default.is_pe?
                                  'pe'
                                else
                                  'agent'
                                end
end

#find_install_versionObject



116
117
118
# File 'lib/beaker/puppet_install_helper.rb', line 116

def find_install_version
  ENV['BEAKER_PUPPET_AGENT_VERSION'] || ENV['PUPPET_INSTALL_VERSION'] || ENV['PUPPET_VERSION']
end

#run_puppet_install_helper(type_arg = find_install_type, version = find_install_version) ⇒ Object



5
6
7
# File 'lib/beaker/puppet_install_helper.rb', line 5

def run_puppet_install_helper(type_arg = find_install_type, version = find_install_version)
  run_puppet_install_helper_on(hosts, type_arg, version)
end

#run_puppet_install_helper_on(hosts, type_arg = find_install_type, version = find_install_version) ⇒ Object

Takes a host(s) object, install type string, and install version string.



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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/beaker/puppet_install_helper.rb', line 10

def run_puppet_install_helper_on(hosts, type_arg = find_install_type, version = find_install_version)
  type = type_arg || find_install_type

  # Short circuit based on rspec-system and beaker variables
  if (ENV['RS_PROVISION'] == 'no') || (ENV['BEAKER_provision'] == 'no')
    configure_type_defaults_on(hosts)
    return
  end

  # Example environment variables to be read:
  # BEAKER_PUPPET_COLLECTION=pc1 <-- for latest 4.x
  # BEAKER_PUPPET_COLLECTION=puppet5 <-- for latest 5.x
  # BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_PUPPET_AGENT_VERSION=5.3.1 <-- for specific version
  # BEAKER_PUPPET_COLLECTION=puppet6-nightly <-- for latest nightly build
  # BEAKER_PUPPET_AGENT_SHA=0ed2bbc918326263da9d97d0361a9e9303b52938 <-- for specific dev build

  # Ensure windows 2003 is always set to 32 bit
  Array(hosts).each do |host|
    host['install_32'] = true if host['platform'] =~ /windows-2003/i
  end

  case type
  when 'pe'
    # These will skip hosts that are not supported
    install_pe_on(Array(hosts), options.merge('pe_ver' => ENV['BEAKER_PE_VER'],
                                              'puppet_agent_version' => version))
    install_ca_certs_on(Array(hosts))
  when 'foss'
    opts = options.merge(version: version,
                         default_action: 'gem_install')
    hosts.each do |host|
      if hosts_with_role(hosts, 'master').length>0 then
        next if host == master
      end
      # XXX install_puppet_on() will call install_puppet_agent_on() if there
      # is a :version option >= 4.x passed, but does foss by default.
      install_puppet_on(host, opts)
    end
    if hosts_with_role(hosts, 'master').length>0 then
      # TODO Make the puppetserver code work with puppet5/puppet6
      # install puppetserver
      install_puppetlabs_release_repo( master, 'pc1' )
      master.install_package('puppetserver')
      on(master, puppet('resource', 'service', 'puppetserver', 'ensure=running'))
      agents.each do |agent|
        on(agent, puppet('resource', 'host', 'puppet', 'ensure=present', "ip=#{master.get_ip}"))
        on(agent, puppet('agent', '--test'), :acceptable_exit_codes => [0,1])
      end
      master['distmoduledir'] = on(master, puppet('config', 'print', 'modulepath')).stdout.split(':')[0]
      sign_certificate_for(agents)
      run_agent_on(agents)
    end
    # XXX install_puppet_on() will only add_aio_defaults_on when the nodeset
    # type == 'aio', but we don't want to depend on that.
    if opts[:version] && !version_is_less(opts[:version], '4.0.0')
      add_aio_defaults_on(hosts)
      add_puppet_paths_on(hosts)
    end
    Array(hosts).each do |host|
      if hosts_with_role(hosts, 'master').length>0 then
        next if host == master
      end
      if fact_on(host, 'osfamily') != 'windows'
        on host, "mkdir -p #{host['distmoduledir']}"
        # XXX Maybe this can just be removed? What PE/puppet version needs
        # it?
        on host, "touch #{host.puppet['hiera_config']}"
      end
      if fact_on(host, 'operatingsystem') == 'Debian'
        on host, "echo 'export PATH=/var/lib/gems/1.8/bin/:${PATH}' >> ~/.bashrc"
      end
      if fact_on(host, 'operatingsystem') == 'Solaris'
        on host, "echo 'export PATH=/opt/puppet/bin:/var/ruby/1.8/gem_home/bin:${PATH}' >> ~/.bashrc"
      end
    end
  when 'agent'
    if find_agent_sha.nil?
      install_puppet_agent_on(hosts, options.merge(version: version))
    else
      opts = options.merge(puppet_agent_sha: find_agent_sha,
                           puppet_agent_version: ENV['PUPPET_AGENT_SUITE_VERSION'] || find_agent_sha)
      install_puppet_agent_dev_repo_on(hosts, opts)
    end

    # XXX install_puppet_agent_on() will only add_aio_defaults_on when the
    # nodeset type == 'aio', but we don't want to depend on that.
    add_aio_defaults_on(hosts)
    add_puppet_paths_on(hosts)
  else
    raise ArgumentError, "Type must be pe, foss, or agent; got #{type.inspect}"
  end
end