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.



39
40
41
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 39

def tmp_dir
  @tmp_dir
end

Instance Method Details

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



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 81

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



201
202
203
204
205
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 201

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

#create_sandboxObject



191
192
193
194
195
196
197
198
199
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 191

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



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

def init_command
end

#install_busserObject

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 171

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

#install_commandObject

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



95
96
97
98
99
100
101
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
# File 'lib/kitchen/provisioner/puppet_agent.rb', line 95

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

#prepare_commandObject



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

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



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

def run_command
  if !config[:puppet_agent_command].nil?
    return config[:puppet_agent_command]
  else
    [
      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_verbose_flag,
      puppet_debug_flag
    ].join(' ')
  end
end