Class: Kitchen::Provisioner::PuppetAgent

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/provisioner/puppet_agent.rb

Overview

Puppet Agent provisioner.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tmp_dirObject

Returns the value of attribute tmp_dir.



41
42
43
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 41

def tmp_dir
  @tmp_dir
end

Instance Method Details

#calculate_path(path, type = :directory) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 88

def calculate_path(path, type = :directory)
  base = config[:test_base_path]
  candidates = []
  candidates << File.join(base, instance.suite.name, 'puppet', path)
  candidates << File.join(base, instance.suite.name, path)
  candidates << File.join(base, path)
  candidates << File.join(Dir.pwd, path)

  candidates.find do |c|
    type == :directory ? File.directory?(c) : File.file?(c)
  end
end

#cleanup_sandboxObject



204
205
206
207
208
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 204

def cleanup_sandbox
  return if sandbox_path.nil?
  debug("Cleaning up local sandbox in #{sandbox_path}")
  FileUtils.rmtree(sandbox_path)
end

#create_sandboxObject



194
195
196
197
198
199
200
201
202
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 194

def create_sandbox
  super
  debug("Creating local sandbox in #{sandbox_path}")

  yield if block_given?

  prepare_puppet_config
  info('Finished Preparing files for transfer')
end

#init_commandObject



192
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 192

def init_command; end

#install_busserObject

rubocop:enable Metrics/CyclomaticComplexity



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 175

def install_busser
  return unless config[:require_chef_for_busser]
  <<-INSTALL
    #{Util.shell_helpers}
    # install chef omnibus so that busser works as this is needed to run tests :(
    # TODO: work out how to install enough ruby
    # and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
    # whole chef client
    if [ ! -d "/opt/chef" ]
    then
      echo "-----> Installing Chef Omnibus to install busser to run tests"
      do_download #{chef_url} /tmp/install.sh
      #{sudo('sh')} /tmp/install.sh
    fi
  INSTALL
end

#install_commandObject

rubocop:disable Metrics/CyclomaticComplexity



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 102

def install_command
  return unless config[:require_puppet_omnibus] || config[:require_puppet_repo]
  if config[:require_puppet_omnibus]
    info('Installing puppet using puppet omnibus')
    version = ''
    version = "-v #{config[:puppet_version]}" if config[:puppet_version]
    <<-INSTALL
      #{Util.shell_helpers}

      if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then
        echo "-----> Installing Puppet Omnibus"
        do_download #{config[:puppet_omnibus_url]} /tmp/puppet_install.sh
        #{sudo('sh')} /tmp/puppet_install.sh #{version}
      fi
      #{install_busser}
    INSTALL
  else
    case puppet_platform
    when 'debian', 'ubuntu'
      info("Installing puppet on #{puppet_platform}")
      <<-INSTALL
        if [ ! $(which puppet) ]; then
          #{sudo('apt-get')} -y install wget
          #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
          #{sudo('dpkg')} -i #{puppet_apt_repo_file}
          #{update_packages_debian_cmd}
          #{sudo_env('apt-get')} -y install facter#{facter_debian_version}
          #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
          #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
        fi
        #{install_busser}
      INSTALL
    when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
      info("Installing puppet on #{puppet_platform}")
      <<-INSTALL
        if [ ! $(which puppet) ]; then
          #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
          #{update_packages_redhat_cmd}
          #{sudo('yum')} -y install puppet#{puppet_redhat_version}
        fi
        #{install_busser}
      INSTALL
    else
      info('Installing puppet, will try to determine platform os')
      <<-INSTALL
        if [ ! $(which puppet) ]; then
          if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
            #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
            #{update_packages_redhat_cmd}
            #{sudo('yum')} -y install puppet#{puppet_redhat_version}
          else
            if [ -f /etc/system-release ] || grep -q 'Amazon Linux' /etc/system-release; then
              #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
              #{update_packages_redhat_cmd}
              #{sudo('yum')} -y install puppet#{puppet_redhat_version}
            else
              #{sudo('apt-get')} -y install wget
              #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
              #{sudo('dpkg')} -i #{puppet_apt_repo_file}
              #{update_packages_debian_cmd}
              #{sudo('apt-get')} -y install facter#{facter_debian_version}
              #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
              #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
            fi
          fi
        fi
        #{install_busser}
      INSTALL
    end
  end
end

#prepare_commandObject



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 210

def prepare_command
  commands = []

  if puppet_config
    commands << [
      sudo('cp'),
      File.join(config[:root_path], 'puppet.conf'),
      '/etc/puppet'
    ].join(' ')
  end

  command = commands.join(' && ')
  debug(command)
  command
end

#run_commandObject



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 226

def run_command
  return config[:puppet_agent_command] unless config[:puppet_agent_command].nil?
  [
    custom_facts,
    sudo_env('puppet'),
    'agent',
    puppet_server_flag,
    "--waitforcert=#{config[:puppet_waitforcert]}",
    puppet_masterport_flag,
    puppet_certname_flag,
    puppet_digest_flag,
    puppet_detailed_exitcodes_flag,
    puppet_logdest_flag,
    puppet_test_flag,
    puppet_onetime_flag,
    puppet_no_daemonize_flag,
    puppet_noop_flag,
    puppet_environment_flag,
    puppet_verbose_flag,
    puppet_debug_flag,
    puppet_whitelist_exit_code
  ].compact.join(' ')
end