Class: Puppet::ModuleTool::Applications::Uninstaller

Inherits:
Application show all
Includes:
Errors
Defined in:
lib/puppet/module_tool/applications/uninstaller.rb

Constant Summary

Constants included from Util::Colors

Util::Colors::BG_BLUE, Util::Colors::BG_CYAN, Util::Colors::BG_GREEN, Util::Colors::BG_HBLUE, Util::Colors::BG_HCYAN, Util::Colors::BG_HGREEN, Util::Colors::BG_HMAGENTA, Util::Colors::BG_HRED, Util::Colors::BG_HWHITE, Util::Colors::BG_HYELLOW, Util::Colors::BG_MAGENTA, Util::Colors::BG_RED, Util::Colors::BG_WHITE, Util::Colors::BG_YELLOW, Util::Colors::BLACK, Util::Colors::BLUE, Util::Colors::CYAN, Util::Colors::Colormap, Util::Colors::GREEN, Util::Colors::HBLACK, Util::Colors::HBLUE, Util::Colors::HCYAN, Util::Colors::HGREEN, Util::Colors::HMAGENTA, Util::Colors::HRED, Util::Colors::HWHITE, Util::Colors::HYELLOW, Util::Colors::MAGENTA, Util::Colors::RED, Util::Colors::RESET, Util::Colors::WHITE, Util::Colors::YELLOW

Instance Attribute Summary

Attributes inherited from Application

#options

Instance Method Summary collapse

Methods inherited from Application

#discuss, #load_metadata!, #metadata, #parse_filename, run

Methods included from Util::Colors

#colorize, #console_color, #html_color

Constructor Details

#initialize(name, options) ⇒ Uninstaller

Returns a new instance of Uninstaller.



6
7
8
9
10
11
12
13
14
15
# File 'lib/puppet/module_tool/applications/uninstaller.rb', line 6

def initialize(name, options)
  @name        = name
  @options     = options
  @errors      = Hash.new {|h, k| h[k] = {}}
  @unfiltered  = []
  @installed   = []
  @suggestions = []
  @environment = options[:environment_instance]
  @ignore_changes = options[:force] || options[:ignore_changes]
end

Instance Method Details

#runObject



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
# File 'lib/puppet/module_tool/applications/uninstaller.rb', line 17

def run
  # Disallow anything that invokes md5 to avoid un-friendly termination due to FIPS
  raise _("Module uninstall is prohibited in FIPS mode.") if Facter.value(:fips_enabled)

  results = {
    :module_name       => @name,
    :requested_version => @version,
  }

  begin
    find_installed_module
    validate_module

    FileUtils.rm_rf(@installed.first.path, :secure => true)

    results[:affected_modules] = @installed
    results[:result] = :success
  rescue ModuleToolError => err
    results[:error] = {
      :oneline   => err.message,
      :multiline => err.multiline,
    }
  rescue => e
    results[:error] = {
      :oneline => e.message,
      :multiline => e.respond_to?(:multiline) ? e.multiline : [e.to_s, e.backtrace].join("\n")
    }
  ensure
    results[:result] ||= :failure
  end

  results
end