Puppet Class: dynatrace::role::uninstall_all

Inherits:
dynatrace
Defined in:
manifests/role/uninstall_all.pp

Overview

uninstall_all

Parameters:

  • ensure (Any) (defaults to: 'uninstalled')
  • role_name (Any) (defaults to: 'Dynatrace Server uninstall')
  • installer_bitsize (Any) (defaults to: $dynatrace::server_installer_bitsize)
  • installer_prefix_dir (Any) (defaults to: $dynatrace::server_installer_prefix_dir)
  • installer_file_name (Any) (defaults to: $dynatrace::server_installer_file_name)
  • installer_file_url (Any) (defaults to: $dynatrace::server_installer_file_url)
  • license_file_name (Any) (defaults to: $dynatrace::server_license_file_name)
  • license_file_url (Any) (defaults to: $dynatrace::server_license_file_url)
  • collector_port (Any) (defaults to: $dynatrace::server_collector_port)
  • pwh_connection_hostname (Any) (defaults to: $dynatrace::server_pwh_connection_hostname)
  • pwh_connection_port (Any) (defaults to: $dynatrace::server_pwh_connection_port)
  • pwh_connection_dbms (Any) (defaults to: $dynatrace::server_pwh_connection_dbms)
  • pwh_connection_database (Any) (defaults to: $dynatrace::server_pwh_connection_database)
  • pwh_connection_username (Any) (defaults to: $dynatrace::server_pwh_connection_username)
  • pwh_connection_password (Any) (defaults to: $dynatrace::server_pwh_connection_password)
  • dynatrace_owner (Any) (defaults to: $dynatrace::dynatrace_owner)
  • dynatrace_group (Any) (defaults to: $dynatrace::dynatrace_group)
  • php_config_file_path (Any) (defaults to: $dynatrace::php_one_agent_php_config_file_path)
  • php_config_file_name (Any) (defaults to: $dynatrace::php_one_agent_php_config_file_name)


2
3
4
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
# File 'manifests/role/uninstall_all.pp', line 2

class dynatrace::role::uninstall_all (
  $ensure                  = 'uninstalled',
  $role_name               = 'Dynatrace Server uninstall',
  $installer_bitsize       = $dynatrace::server_installer_bitsize,
  $installer_prefix_dir    = $dynatrace::server_installer_prefix_dir,
  $installer_file_name     = $dynatrace::server_installer_file_name,
  $installer_file_url      = $dynatrace::server_installer_file_url,
  $license_file_name       = $dynatrace::server_license_file_name,
  $license_file_url        = $dynatrace::server_license_file_url,
  $collector_port          = $dynatrace::server_collector_port,
  $pwh_connection_hostname = $dynatrace::server_pwh_connection_hostname,
  $pwh_connection_port     = $dynatrace::server_pwh_connection_port,
  $pwh_connection_dbms     = $dynatrace::server_pwh_connection_dbms,
  $pwh_connection_database = $dynatrace::server_pwh_connection_database,
  $pwh_connection_username = $dynatrace::server_pwh_connection_username,
  $pwh_connection_password = $dynatrace::server_pwh_connection_password,
  $dynatrace_owner         = $dynatrace::dynatrace_owner,
  $dynatrace_group         = $dynatrace::dynatrace_group,
  $php_config_file_path    = $dynatrace::php_one_agent_php_config_file_path,
  $php_config_file_name    = $dynatrace::php_one_agent_php_config_file_name
) inherits dynatrace {

  case $::kernel {
    'Linux': {
      $services_to_manage_array = $dynatrace::services_to_manage_array
    }
    default: {}
  }

  $installation_ensure = $ensure ? {
    'absent'  => 'uninstalled',
    default   => 'installed',
  }

  $service_ensure = $ensure ? {
    'absent'  => 'stopped',
    default   => 'stopped',
  }

  $installer_cache_dir = "${settings::vardir}/dynatrace"
  $install_link   = "${installer_prefix_dir}/dynatrace"
  $symlink        = "${installer_prefix_dir}/dynatrace"
  $php_ini_file   = "${php_config_file_path}/${php_config_file_name}"
  $one_agent_dir  = "${installer_prefix_dir}/dynatrace-oneagent-*"

  #stop all Dynatrace processes
  include dynatrace::role::stop_all_processes

  #removing folders and links
  exec {"remove directory using symlink=${symlink}":
    # remove directory using symlink (Puppet file resource does not work sometimes in this case)
    command => "rm -rf \"$(readlink ${symlink})\"; rm -rf ${symlink}",
    path    => ['/usr/bin', '/usr/sbin', '/bin', '/sbin'],
    onlyif  => ["test -L ${symlink}"],
  }

  -> file {"remove directory by symlink=${symlink}":
    path    => $symlink,
    recurse => true,
    purge   => true,
    force   => true,
  }

  -> tidy { 'clean /tmp folder from dynatrace files':
    path    => '/tmp',
    recurse => 1,
    matches => [ 'dt*', 'java_*', 'dynaTrace*.zip' ],
  }

  -> tidy { 'clean dynatrace temp folder':
    path    => '/tmp/hsperfdata_dynatrace',
    recurse => 1,
    matches => [ '[0-9]*' ],
  }

  -> tidy { 'clean temp folder':
    path    => '/tmp/hsperfdata_root',
    recurse => 1,
    matches => [ '[0-9]*' ],
  }

  file { $installer_cache_dir:
    ensure  => absent,
    path    => $installer_cache_dir,
    recurse => true,
    purge   => true,
    force   => true,
  }

  file {'remove tmp dynatrace directory':
    ensure  => absent,
    path    => '/tmp/hsperfdata_dynatrace',
    recurse => true,
    purge   => true,
    force   => true,
  }

  -> file {'remove tmp directory':
    ensure  => absent,
    path    => '/tmp/hsperfdata_root',
    recurse => true,
    purge   => true,
    force   => true,
  }

  $services_to_manage_array.each |$x| {
    file {"remove /etc/init.d/${x} link":
      ensure  => absent,
      path    => "/etc/init.d/${x}",
      recurse => true,
      purge   => true,
      force   => true,
    }
  }

  #removing phpOneAgent
  exec {"remove phpOneAgent directory ${one_agent_dir}":
    # remove directory using symlink (Puppet file resource does not work sometimes in this case)
    command => "rm -rf ${one_agent_dir}",
    path    => ['/usr/bin', '/usr/sbin', '/bin', '/sbin'],
    onlyif  => ["test -d ${one_agent_dir}"],
  }

  file { $php_ini_file :
    ensure => file,
  }
  -> exec {'remove phpagent.tenant from phpOneAgent configuration':
  command => "/bin/sed -i '/^phpagent.tenant/d' ${$php_ini_file}",
  onlyif  => "/bin/grep '^phpagent.tenant' ${$php_ini_file}",
  }
  -> exec {'remove phpagent.server from phpOneAgent configuration':
  command => "/bin/sed -i '/^phpagent.server*/d' ${$php_ini_file}",
  onlyif  => "/bin/grep '^phpagent.server' ${$php_ini_file}",
  }
  -> exec {'remove phpagent.agentname from phpOneAgent configuration':
  command => "/bin/sed -i '/^phpagent.agentname*/d' ${$php_ini_file}",
  onlyif  => "/bin/grep '^phpagent.agentname' ${$php_ini_file}",
  }
  -> exec {'remove extension from phpOneAgent configuration':
  command => "/bin/sed -i '/^extension\s\?=\s\?.*liboneagentloader.so$/d' ${$php_ini_file}",
  onlyif  => "/bin/grep '^extension\s\?=\s\?.*liboneagentloader.so$' ${$php_ini_file}",
  }


}