Class: Kitchen::Provisioner::PuppetApply

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

Overview

Puppet Apply provisioner.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tmp_dirObject

Returns the value of attribute tmp_dir.



46
47
48
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 46

def tmp_dir
  @tmp_dir
end

Instance Method Details

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



169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 169

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



549
550
551
552
553
554
555
556
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 549

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

#create_sandboxObject



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 531

def create_sandbox
  super
  debug("Creating local sandbox in #{sandbox_path}")
  yield if block_given?
  prepare_modules
  prepare_manifests
  prepare_files
  prepare_facter_file
  prepare_facts
  prepare_puppet_config
  prepare_hiera_config
  prepare_fileserver_config
  prepare_hiera_data
  prepare_enc
  prepare_spec_files
  info('Finished Preparing files for transfer')
end

#custom_install_commandObject



509
510
511
512
513
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 509

def custom_install_command
  "    \#{config[:custom_install_command]}\n  INSTALL\nend\n"

#custom_pre_install_commandObject



503
504
505
506
507
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 503

def custom_pre_install_command
  "    \#{config[:custom_pre_install_command]}\n  INSTALL\nend\n"

#hiera_packageObject



464
465
466
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 464

def hiera_package
  "#{config[:hiera_package]}#{puppet_hiera_debian_version}"
end

#init_commandObject



515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 515

def init_command
  todelete = %w(modules manifests files hiera hiera.yaml facter spec enc)
             .map { |dir| File.join(config[:root_path], dir) }
  todelete += [hiera_data_remote_path,
               '/etc/hiera.yaml',
               "#{puppet_dir}/hiera.yaml",
               spec_files_remote_path.to_s,
               "#{puppet_dir}/fileserver.conf"]
  todelete << File.join(puppet_dir, config[:puppet_environment]) if config[:puppet_environment]
  cmd = "#{sudo(rm_command_paths(todelete))};"
  cmd += " #{mkdir_command} #{config[:root_path]};"
  cmd += " #{sudo(mkdir_command)} #{puppet_dir}"
  debug(cmd)
  cmd
end

#install_busserObject



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 407

def install_busser
  return unless config[:require_chef_for_busser]
  info("Install busser on #{puppet_platform}")
  case puppet_platform
  when /^windows.*/
    # https://raw.githubusercontent.com/opscode/knife-windows/master/lib/chef/knife/bootstrap/windows-chef-client-msi.erb

    "      $webclient = New-Object System.Net.WebClient;  $webclient.DownloadFile('https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-windows-11.12.8-1.windows.msi','chef-windows-11.12.8-1.windows.msi')\n      msiexec /qn /i chef-windows-11.12.8-1.windows.msi\n\n      cmd.exe /C \"SET PATH=%PATH%;`\"C:\\\\opscode\\\\chef\\\\embedded\\\\bin`\";`\"C:\\\\tmp\\\\busser\\\\gems\\\\bin`\"\"\n\n    INSTALL\n  else\n    <<-INSTALL\n    \#{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      \#{export_http_proxy_parm}\n      \#{export_https_proxy_parm}\n      do_download \#{chef_url} /tmp/install.sh\n      \#{sudo('sh')} /tmp/install.sh\n    fi\n    INSTALL\n  end\nend\n"

#install_commandObject

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 183

def install_command
  return unless config[:require_puppet_collections] || config[:require_puppet_repo] || config[:require_puppet_omnibus]
  if config[:require_puppet_omnibus]
    install_omnibus_command
  elsif config[:require_puppet_collections]
    install_command_collections
  else
    case puppet_platform
    when 'debian', 'ubuntu'
      info("Installing puppet on #{config[:platform]}")
      # need to add a CR to avoid trouble with proxy settings concatenation

      "\n        \#{custom_pre_install_command}\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_env('apt-get')} -y install puppet-common\#{puppet_debian_version}\n          \#{sudo_env('apt-get')} -y install puppet\#{puppet_debian_version}\n          \#{install_hiera}\n        fi\n        \#{install_eyaml}\n        \#{install_eyaml_gpg}\n        \#{install_deep_merge}\n        \#{install_busser}\n        \#{custom_install_command}\n      INSTALL\n    when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'\n      info(\"Installing puppet from yum on \#{puppet_platform}\")\n      # need to add a CR to avoid trouble with proxy settings concatenation\n      <<-INSTALL\n\n        \#{custom_pre_install_command}\n        if [ ! $(which puppet) ]; then\n          \#{install_puppet_yum_repo}\n        fi\n        \#{install_eyaml}\n        \#{install_eyaml_gpg}\n        \#{install_deep_merge}\n        \#{install_busser}\n        \#{custom_install_command}\n      INSTALL\n    when /^windows.*/\n      info(\"Installing puppet on \#{puppet_platform}\")\n      info('Powershell is not recognised by core test-kitchen assuming it is present') unless powershell_shell?\n      <<-INSTALL\n        if(Get-Command puppet -ErrorAction 0) { return; }\n        $architecture = if( [Environment]::Is64BitOperatingSystem ) { '-x64' } else { '' }\n        if( '\#{puppet_windows_version}' -eq 'latest' ) {\n            $MsiUrl = \"https://downloads.puppetlabs.com/windows/puppet${architecture}-latest.msi\"\n        } else {\n            $MsiUrl = \"https://downloads.puppetlabs.com/windows/puppet-\#{puppet_windows_version}${architecture}.msi\"\n        }\n        wget $MsiUrl -UseBasicParsing -OutFile \"C:/puppet.msi\" \#{posh_proxy_parm}\n        $process = Start-Process -FilePath msiexec.exe -Wait -PassThru -ArgumentList '/qn', '/norestart', '/i', 'C:\\\\puppet.msi'\n        if ($process.ExitCode -ne 0) {\n            Write-Host \"Installer failed.\"\n            Exit 1\n        }\n\n        \#{install_busser}\n      INSTALL\n    else\n      info('Installing puppet, will try to determine platform os')\n      # need to add a CR to avoid trouble with proxy settings concatenation\n      <<-INSTALL\n\n        \#{custom_pre_install_command}\n        if [ ! $(which puppet) ]; then\n          if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then\n              \#{install_puppet_yum_repo}\n          else\n            if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then\n               \#{install_puppet_yum_repo}\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_env('apt-get')} -y install facter\#{facter_debian_version}\n              \#{sudo_env('apt-get')} -y install puppet-common\#{puppet_debian_version}\n              \#{sudo_env('apt-get')} -y install puppet\#{puppet_debian_version}\n              \#{install_hiera}\n            fi\n          fi\n        fi\n        \#{install_eyaml}\n        \#{install_eyaml_gpg}\n        \#{install_deep_merge}\n        \#{install_busser}\n        \#{custom_install_command}\n      INSTALL\n    end\n  end\nend\n"

#install_command_collectionsObject

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 283

def install_command_collections
  case puppet_platform
  when 'debian', 'ubuntu'
    info("Installing Puppet Collections on #{puppet_platform}")
    "\n    \#{Util.shell_helpers}\n    \#{custom_pre_install_command}\n    if [ ! -d \"\#{config[:puppet_coll_remote_path]}\" ]; then\n      if [ ! -f \"\#{config[:puppet_apt_collections_repo]}\" ]; then\n        \#{sudo('apt-get')} -y install wget\n        \#{sudo('wget')} \#{wget_proxy_parm} \#{config[:puppet_apt_collections_repo]}\n      fi\n      \#{sudo('dpkg')} -i \#{puppet_apt_coll_repo_file}\n      \#{sudo('apt-get')} update\n      \#{sudo_env('apt-get')} -y install puppet-agent\#{puppet_debian_version}\n    fi\n    \#{install_eyaml(\"\#{config[:puppet_coll_remote_path]}/puppet/bin/gem\")}\n    \#{install_eyaml_gpg(\"\#{config[:puppet_coll_remote_path]}/puppet/bin/gem\")}\n    \#{install_deep_merge}\n    \#{install_busser}\n    \#{custom_install_command}\n    INSTALL\n  when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'\n    info(\"Installing Puppet Collections on \#{puppet_platform}\")\n    <<-INSTALL\n\n    \#{Util.shell_helpers}\n    if [ ! -d \"\#{config[:puppet_coll_remote_path]}\" ]; then\n      echo \"-----> \#{sudo_env('yum')} -y install \#{config[:puppet_yum_collections_repo]}\"\n      \#{sudo_env('yum')} -y install \#{config[:puppet_yum_collections_repo]}\n      \#{sudo_env('yum')} -y install puppet-agent\#{puppet_redhat_version}\n    fi\n    \#{install_eyaml(\"\#{config[:puppet_coll_remote_path]}/puppet/bin/gem\")}\n    \#{install_eyaml_gpg(\"\#{config[:puppet_coll_remote_path]}/puppet/bin/gem\")}\n    \#{install_deep_merge}\n    \#{install_busser}\n    \#{custom_install_command}\n    INSTALL\n  when /^windows.*/\n    info(\"Installing Puppet Collections on \#{puppet_platform}\")\n    <<-INSTALL\n      if(Get-Command puppet -ErrorAction 0) { return; }\n      $architecture = if( [Environment]::Is64BitOperatingSystem ) { 'x64' } else { 'x86' }\n      if( '\#{puppet_windows_version}' -eq 'latest' ) {\n          $MsiUrl = \"https://downloads.puppetlabs.com/windows/puppet-agent-${architecture}-latest.msi\"\n      } else {\n          $MsiUrl = \"https://downloads.puppetlabs.com/windows/puppet-agent-\#{puppet_windows_version}-${architecture}.msi\"\n      }\n      wget $MsiUrl -UseBasicParsing -OutFile \"C:/puppet-agent.msi\" \#{posh_proxy_parm}\n      $process = Start-Process -FilePath msiexec.exe -Wait -PassThru -ArgumentList '/qn', '/norestart', '/i', 'C:\\\\puppet-agent.msi'\n      if ($process.ExitCode -ne 0) {\n          Write-Host \"Installer failed.\"\n          Exit 1\n      }\n\n      \#{install_busser}\n    INSTALL\n  else\n    info('Installing Puppet Collections, will try to determine platform os')\n    <<-INSTALL\n\n      \#{Util.shell_helpers}\n      \#{custom_pre_install_command}\n      if [ ! -d \"\#{config[:puppet_coll_remote_path]}\" ]; then\n        if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ] || \\\n           [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then\n          echo \"-----> \#{sudo_env('yum')} -y install \#{config[:puppet_yum_collections_repo]}\"\n          \#{sudo_env('yum')} -y install \#{config[:puppet_yum_collections_repo]}\n          \#{sudo_env('yum')} -y install puppet-agent\#{puppet_redhat_version}\n        else\n          \#{sudo('apt-get')} -y install wget\n          \#{sudo('wget')} \#{wget_proxy_parm} \#{config[:puppet_apt_collections_repo]}\n          \#{sudo('dpkg')} -i \#{puppet_apt_coll_repo_file}\n          \#{sudo('apt-get')} update\n          \#{sudo_env('apt-get')} -y install puppet-agent\#{puppet_debian_version}\n        fi\n      fi\n      \#{install_eyaml(\"\#{config[:puppet_coll_remote_path]}/puppet/bin/gem\")}\n      \#{install_eyaml_gpg(\"\#{config[:puppet_coll_remote_path]}/puppet/bin/gem\")}\n      \#{install_deep_merge}\n      \#{install_busser}\n      \#{custom_install_command}\n    INSTALL\n  end\nend\n"

#install_deep_mergeObject



370
371
372
373
374
375
376
377
378
379
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 370

def install_deep_merge
  return unless config[:hiera_deep_merge]
  "    # Support for hash merge lookups to recursively merge hash keys\n    if [[ $(\#{sudo('gem')} list deep_merge -i) == 'false' ]]; then\n      echo '-----> Installing deep_merge to provide deep_merge of hiera hashes'\n      \#{sudo('gem')} install \#{gem_proxy_parm} --no-ri --no-rdoc deep_merge\n    fi\n  INSTALL\nend\n"

#install_eyaml(gem_cmd = 'gem') ⇒ Object



381
382
383
384
385
386
387
388
389
390
391
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 381

def install_eyaml(gem_cmd = 'gem')
  return unless config[:hiera_eyaml]
  "    # A backend for Hiera that provides per-value asymmetric encryption of sensitive data\n    if [[ $(\#{sudo(gem_cmd)} list hiera-eyaml -i) == 'false' ]]; then\n      echo '-----> Installing hiera-eyaml to provide encryption of hiera data'\n      \#{sudo(gem_cmd)} install \#{gem_proxy_parm} --no-ri --no-rdoc highline -v 1.6.21\n      \#{sudo(gem_cmd)} install \#{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml\n    fi\n  INSTALL\nend\n"

#install_eyaml_gpg(gem_cmd = 'gem') ⇒ Object



393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 393

def install_eyaml_gpg(gem_cmd = 'gem')
  return unless config[:hiera_eyaml_gpg]
  "    # A backend for Hiera that provides per-value asymmetric encryption of sensitive data\n    if [[ $(\#{sudo(gem_cmd)} list hiera-eyaml-gpg -i) == 'false' ]]; then\n      echo '-----> Installing hiera-eyaml-gpg to provide encryption of hiera data'\n      \#{sudo(gem_cmd)} install \#{gem_proxy_parm} --no-ri --no-rdoc highline -v 1.6.21\n      \#{sudo(gem_cmd)} install \#{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml\n      \#{sudo(gem_cmd)} install \#{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml-gpg\n      \#{sudo(gem_cmd)} install \#{gem_proxy_parm} --no-ri --no-rdoc ruby_gpg\n    fi\n  INSTALL\nend\n"

#install_hieraObject



457
458
459
460
461
462
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 457

def install_hiera
  return unless config[:install_hiera]
  "  \#{sudo_env('apt-get')} -y install \#{hiera_package}\n  INSTALL\nend\n"

#install_omnibus_commandObject



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 439

def install_omnibus_command
  info('Installing puppet using puppet omnibus')

  version = ''
  version = "-v #{config[:puppet_version]}" unless config[:puppet_version].nil?

  "  \#{Util.shell_helpers}\n  if [ ! $(which puppet) ]; then\n    echo \"-----> Installing Puppet Omnibus\"\n    \#{export_http_proxy_parm}\n    \#{export_https_proxy_parm}\n    do_download \#{config[:puppet_omnibus_url]} /tmp/install_puppet.sh\n    \#{sudo_env('sh')} /tmp/install_puppet.sh \#{version}\n  fi\n  INSTALL\nend\n"

#install_puppet_yum_repoObject

/bin/wget -P /etc/pki/rpm-gpg/ yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs changed to curl



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 471

def install_puppet_yum_repo
  "    rhelversion=$(cat /etc/redhat-release | grep 'release 7')\n    # For CentOS7/RHEL7 the rdo release contains puppetlabs repo, creating conflict. Create temp-repo\n    \#{sudo_env('curl')} -o /etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs\n    if [ -n \"$rhelversion\" ]; then\n    echo '[puppettemp-products]\n    name=Puppet Labs Products - \\$basearch\n    baseurl=http://yum.puppetlabs.com/el/7/products/\\$basearch\n    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs\n    enabled=0\n    gpgcheck=1\n    [puppettemp-deps]\n    name=Puppet Labs Dependencies - \\$basearch\n    baseurl=http://yum.puppetlabs.com/el/7/dependencies/\\$basearch\n    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs\n    enabled=0\n    gpgcheck=1' | sudo tee /etc/yum.repos.d/puppettemp.repo > /dev/null\n    sudo sed -i 's/^[ \\t]*//' /etc/yum.repos.d/puppettemp.repo\n      \#{update_packages_redhat_cmd}\n      \#{sudo_env('yum')} -y --enablerepo=puppettemp-products --enablerepo=puppettemp-deps install puppet\#{puppet_redhat_version}\n      # Clean up temporary puppet repo\n      sudo rm -rf /etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs\n      sudo rm -rf /etc/yum.repos.d/puppettemp.repo\n    else\n      \#{sudo('rpm')} -ivh \#{proxy_parm} \#{puppet_yum_repo}\n      \#{update_packages_redhat_cmd}\n      \#{sudo_env('yum')} -y install puppet\#{puppet_redhat_version}\n    fi\n  INSTALL\nend\n"

#prepare_commandObject

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 559

def prepare_command
  commands = []
  if puppet_git_init
    commands << [
      sudo('rm -rf'), '/etc/puppet'
    ].join(' ')

    commands << [
      sudo('git clone'), puppet_git_init, '/etc/puppet'
    ].join(' ')
  end

  if puppet_git_pr
    commands << [
      sudo('git'),
      '--git-dir=/etc/puppet/.git/',
      'fetch -f',
      'origin',
      "pull/#{puppet_git_pr}/head:pr_#{puppet_git_pr}"
    ].join(' ')

    commands << [
      sudo('git'),
      '--git-dir=/etc/puppet/.git/',
      '--work-tree=/etc/puppet/',
      'checkout',
      "pr_#{puppet_git_pr}"
    ].join(' ')
  end

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

  if hiera_config
    commands << [
      sudo(cp_command), File.join(config[:root_path], 'hiera.yaml'), '/etc/'
    ].join(' ')

    commands << [
      sudo(cp_command), File.join(config[:root_path], 'hiera.yaml'), hiera_config_dir
    ].join(' ')
  end

  if fileserver_config
    commands << [
      sudo(cp_command),
      File.join(config[:root_path], 'fileserver.conf'),
      puppet_dir
    ].join(' ')
  end

  if hiera_data
    commands << [
      sudo(mkdir_command), hiera_data_remote_path
    ].join(' ')
    commands << [
      sudo("#{cp_command} -r"), File.join(config[:root_path], 'hiera/*'), hiera_data_remote_path
    ].join(' ')
  end

  if hiera_eyaml
    commands << [
      sudo(mkdir_command), hiera_eyaml_key_remote_path
    ].join(' ')
    commands << [
      sudo("#{cp_command} -r"), File.join(config[:root_path], 'hiera_keys/*'), hiera_eyaml_key_remote_path
    ].join(' ')
  end

  if hiera_eyaml_gpg
    commands << [
      sudo('mkdir -p'), hiera_eyaml_gpg_remote_path
    ].join(' ')
    commands << [
      sudo('cp -r'), File.join(config[:root_path], hiera_eyaml_gpg_recipients), hiera_eyaml_gpg_remote_path
    ].join(' ')
    commands << [
      sudo('cp -r'), File.join(config[:root_path], hiera_eyaml_gpg_secring), hiera_eyaml_gpg_remote_path
    ].join(' ')
    commands << [
      sudo('cp -r'), File.join(config[:root_path], hiera_eyaml_gpg_pubring), hiera_eyaml_gpg_remote_path
    ].join(' ')
  end

  if puppet_environment
    commands << [
      sudo('ln -s '), config[:root_path], File.join(puppet_dir, config[:puppet_environment])
    ].join(' ')
  end

  if spec_files_path && spec_files_remote_path
    commands << [
      sudo(mkdir_command), spec_files_remote_path
    ].join(' ')
    commands << [
      sudo("#{cp_command} -r"), File.join(config[:root_path], 'spec/*'), spec_files_remote_path
    ].join(' ')
  end

  if config[:puppet_enc]
    commands << [
      sudo('chmod 755'), File.join("#{config[:root_path]}/enc", File.basename(config[:puppet_enc]))
    ].join(' ')
  end

  command = powershell? ? commands.join('; ') : commands.join(' && ')
  debug(command)
  command
end

#run_commandObject



674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
# File 'lib/kitchen/provisioner/puppet_apply.rb', line 674

def run_command
  return config[:puppet_apply_command] unless config[:puppet_apply_command].nil?
  result = [
    facterlib,
    custom_facts,
    puppet_manifestdir,
    puppet_cmd,
    'apply',
    File.join(config[:root_path], 'manifests', manifest),
    "--modulepath=#{File.join(config[:root_path], 'modules')}",
    "--fileserverconfig=#{File.join(config[:root_path], 'fileserver.conf')}",
    custom_options,
    puppet_environment_flag,
    puppet_noop_flag,
    puppet_enc_flag,
    puppet_detailed_exitcodes_flag,
    puppet_verbose_flag,
    puppet_debug_flag,
    puppet_logdest_flag,
    puppet_whitelist_exit_code
  ].join(' ')
  if config[:custom_post_apply_command]
    custom_post_apply_trap = "      function custom_post_apply_command {\n        \#{config[:custom_post_apply_command]}\n      }\n      trap custom_post_apply_command EXIT\n    TRAP\n  end\n  result = <<-RUN\n    \#{config[:custom_pre_apply_command]}\n    \#{custom_post_apply_trap}\n    \#{result}\n  RUN\n  info(\"Going to invoke puppet apply with: \#{result}\")\n  result\nend\n"