Puppet Plan: cd4peadm::uninstall

Defined in:
plans/uninstall.pp

Summary

Remove the CD4PE application and all associated data

Overview

This plan will remove CD4PE from the hosts specified in the Hiera config file. This process requires the configured runtime be in a functional state, as it is used to remove the containers, volumes, and network associated with CD4PE. The runtime itself is not removed, to account for it potentially being used for other applications

Parameters:

  • force (Optional[Boolean]) (defaults to: false)

    Uninstall without prompting for confirmation



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
# File 'plans/uninstall.pp', line 10

plan cd4peadm::uninstall(
  Optional[Boolean] $force = false,
) {
  run_plan('cd4peadm::check_bolt_version')

  $config = cd4peadm::config()

  $host = $config['roles']['backend']['targets'][0]

  if(!$force) {
    $prompt_message = @("PROMPT_MESSAGE")
      This plan will remove the CD4PE application and all associated data from '${host}'.
      It will not remove ${config['runtime']}. The ${config['runtime']} runtime will need to be functional
      for this plan to successfully remove all CD4PE components.

      Do you want to continue with uninstalling CD4PE on '${host}'? (yes/no)
      | PROMPT_MESSAGE

    $really_want_to_uninstall = prompt($prompt_message, 'default' => 'no')

    if(!($really_want_to_uninstall == 'yes')) {
      fail_plan('Exiting uninstall')
    }
  }

  $db_role = $config['roles']['database']['services']['postgres']

  $database_info = Cd4peadm::Support_bundle::Database_info.new( {
      'container_name' => $db_role['container']['name'],
      'database_user'  => $db_role['admin_db_username'],
  })

  $roles = $config['roles']
  $container_info = [
    $roles['backend']['services']['pipelinesinfra']['container'],
    $roles['backend']['services']['query']['container'],
    $roles['database']['services']['postgres']['container'],
    $roles['ui']['services']['ui']['container'],
  ]

  $result = run_task(
    'cd4peadm::uninstall',
    # TODO: Currently only supports a single target
    $host,
    {
      'runtime'       => $config['runtime'],
      'backup_dir'    => $config['backup_dir'],
      'containers'    => $container_info,
      '_run_as'       => 'root',
      '_catch_errors' => true,
    }
  )

  # Log the output at debug level so we can at least use
  # bolt-debug.log to see what happened in the event of an issue
  log::debug($result[0].value['message'])

  if($result[0].ok) {
    out::message("Uninstall complete. CD4PE has been removed from '${host}'.")
  } else {
    $error_message = @("ERROR")
      Uninstall failed on '${host}':

      ${$result[0]['_error']['msg']}

      Check the bolt-debug.log for additional details.
      | ERROR
    fail_plan($error_message)
  }
}