Puppet Plan: cd4peadm::upgrade

Defined in:
plans/upgrade.pp

Summary

Upgrade existing CD4PE instance

Overview

This plan will fail if the module version is not newer than the existing install.



5
6
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
64
65
66
67
68
69
70
71
72
73
74
75
# File 'plans/upgrade.pp', line 5

plan cd4peadm::upgrade() {
  run_plan('cd4peadm::check_bolt_version')

  # Get the version of CD4PE on the target so we can
  # determine if we need to run individual upgrade plans
  $hiera_config = loadyaml('data/common.yaml')
  $target = $hiera_config['cd4peadm::config']['targets']['backend'][0]

  $version_from_file_result = run_plan('cd4peadm::read_version_file_from_target', targets => [$target])
  if(!$version_from_file_result.error_set.empty) {
    $error = $version_from_file_result.error_set[0].value[stderr]
    if($error =~ /.*No such file or directory.*/) {
      out::message('Could not determine installed version, assuming < 5.2.0.')
      $installed_version = '5.1.2'
    } else {
      fail_plan("Could not determine version of CD4PE on the target ${target}: ${error}")
    }
  } else {
    $installed_version = chomp($version_from_file_result[0].value[stdout])
  }

  if (versioncmp(cd4peadm::module_version(), $installed_version) <= 0) {
    $not_an_upgrade_error = @("FAILED")
      Current module version ${cd4peadm::module_version()} is not newer than installed version ${installed_version}.

      Make sure the version of puppetlabs-cd4peadm in your Puppetfile is correct and try the upgrade again.
      | FAILED
    fail_plan($not_an_upgrade_error, 'cd4pe/error')
  }

  if (versioncmp($installed_version, '5.2.0') < 0) {
    out::message("Making changes to support upgrading ${installed_version} to 5.2.0 and newer")
    run_plan('cd4peadm::upgrade::ensure_certs_in_hiera')
    run_plan('cd4peadm::upgrade::set_default_config_values')
  }

  $config = cd4peadm::config()

  run_plan('cd4peadm::preflight',
    config => $config,
  )

  run_plan('cd4peadm::install::runtime',
    config => $config,
  )

  run_plan('cd4peadm::install::upload_images',
    config => $config,
  )

  get_target('localhost').set_var('service_will_be_restarted_by_caller', true)
  run_plan('cd4peadm::upload_license',
    config => $config,
  )

  run_plan('cd4peadm::install::roles',
    config => $config,
  )

  run_plan('cd4peadm::install::wait_for_services',
    config => $config,
  )

  run_plan('cd4peadm::upgrade::cleanup',
    config => $config,
  )

  write_file(cd4peadm::module_version(), cd4peadm::version_file_path(), $config['all_targets'], { '_run_as' => 'root' })

  run_plan('cd4peadm::license_check')
}