File: uninstall.rb

package info (click to toggle)
puppet-agent 7.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,092 kB
  • sloc: ruby: 245,074; sh: 456; makefile: 38; xml: 33
file content (89 lines) | stat: -rw-r--r-- 3,340 bytes parent folder | download
1
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
Puppet::Face.define(:module, '1.0.0') do
  action(:uninstall) do
    summary _("Uninstall a puppet module.")
    description <<-EOT
      Uninstalls a puppet module from the modulepath (or a specific
      target directory).
      Note: Module uninstall uses MD5 checksums, which are prohibited on FIPS enabled systems.
    EOT

    returns _("Hash of module objects representing uninstalled modules and related errors.")

    examples <<-'EOT'
      Uninstall a module:

      $ puppet module uninstall puppetlabs-ssh
      Removed /etc/puppetlabs/code/modules/ssh (v1.0.0)

      Uninstall a module from a specific directory:

      $ puppet module uninstall puppetlabs-ssh --modulepath /opt/puppetlabs/puppet/modules
      Removed /opt/puppetlabs/puppet/modules/ssh (v1.0.0)

      Uninstall a module from a specific environment:

      $ puppet module uninstall puppetlabs-ssh --environment development
      Removed /etc/puppetlabs/code/environments/development/modules/ssh (v1.0.0)

      Uninstall a specific version of a module:

      $ puppet module uninstall puppetlabs-ssh --version 2.0.0
      Removed /etc/puppetlabs/code/modules/ssh (v2.0.0)
    EOT

    arguments _("<name>")

    option "--force", "-f" do
      summary _("Force uninstall of an installed module.")
      description <<-EOT
        Force the uninstall of an installed module even if there are local
        changes or the possibility of causing broken dependencies.
      EOT
    end

    option "--ignore-changes", "-c" do
      summary _("Ignore any local changes made. (Implied by --force.)")
      description <<-EOT
        Uninstall an installed module even if there are local changes to it.  (Implied by --force.)
      EOT
    end

    option "--version=" do
      summary _("The version of the module to uninstall")
      description <<-EOT
        The version of the module to uninstall. When using this option, a module
        matching the specified version must be installed or else an error is raised.
      EOT
    end

    when_invoked do |name, options|
      name = name.tr('/', '-')

      Puppet::ModuleTool.set_option_defaults options
      message = if options[:version]
                  module_version = colorize(:cyan, options[:version].sub(/^(?=\d)/, 'v'))
                  _("Preparing to uninstall '%{name}' (%{module_version}) ...") % { name: name, module_version: module_version }
                else
                  _("Preparing to uninstall '%{name}' ...") % { name: name }
                end
      Puppet.notice message
      Puppet::ModuleTool::Applications::Uninstaller.run(name, options)
    end

    when_rendering :console do |return_value|
      if return_value[:result] == :failure
        Puppet.err(return_value[:error][:multiline])
        exit 1
      else
        mod = return_value[:affected_modules].first
        message = if mod.version
                    module_version = colorize(:cyan, mod.version.to_s.sub(/^(?=\d)/, 'v'))
                    _("Removed '%{name}' (%{module_version}) from %{path}") % { name: return_value[:module_name], module_version: module_version, path: mod.modulepath }
                  else
                    _("Removed '%{name}' from %{path}") % { name: return_value[:module_name], path: mod.modulepath }
                  end
        message
      end
    end
  end
end