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 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 147 148 149
|
# encoding: UTF-8
# frozen_string_literal: true
require_relative '../../../puppet/forge'
require_relative '../../../puppet/module_tool/install_directory'
require 'pathname'
Puppet::Face.define(:module, '1.0.0') do
action(:install) do
summary _("Install a module from the Puppet Forge or a release archive.")
description <<-EOT
Installs a module from the Puppet Forge or from a release archive file.
Note: Module install uses MD5 checksums, which are prohibited on FIPS enabled systems.
The specified module will be installed into the directory
specified with the `--target-dir` option, which defaults to the first
directory in the modulepath.
EOT
returns _("Pathname object representing the path to the installed module.")
examples <<-'EOT'
Install a module:
$ puppet module install puppetlabs-vcsrepo
Preparing to install into /etc/puppetlabs/code/modules ...
Downloading from https://forgeapi.puppet.com ...
Installing -- do not interrupt ...
/etc/puppetlabs/code/modules
└── puppetlabs-vcsrepo (v0.0.4)
Install a module to a specific environment:
$ puppet module install puppetlabs-vcsrepo --environment development
Preparing to install into /etc/puppetlabs/code/environments/development/modules ...
Downloading from https://forgeapi.puppet.com ...
Installing -- do not interrupt ...
/etc/puppetlabs/code/environments/development/modules
└── puppetlabs-vcsrepo (v0.0.4)
Install a specific module version:
$ puppet module install puppetlabs-vcsrepo -v 0.0.4
Preparing to install into /etc/puppetlabs/modules ...
Downloading from https://forgeapi.puppet.com ...
Installing -- do not interrupt ...
/etc/puppetlabs/code/modules
└── puppetlabs-vcsrepo (v0.0.4)
Install a module into a specific directory:
$ puppet module install puppetlabs-vcsrepo --target-dir=/opt/puppetlabs/puppet/modules
Preparing to install into /opt/puppetlabs/puppet/modules ...
Downloading from https://forgeapi.puppet.com ...
Installing -- do not interrupt ...
/opt/puppetlabs/puppet/modules
└── puppetlabs-vcsrepo (v0.0.4)
Install a module into a specific directory and check for dependencies in other directories:
$ puppet module install puppetlabs-vcsrepo --target-dir=/opt/puppetlabs/puppet/modules --modulepath /etc/puppetlabs/code/modules
Preparing to install into /opt/puppetlabs/puppet/modules ...
Downloading from https://forgeapi.puppet.com ...
Installing -- do not interrupt ...
/opt/puppetlabs/puppet/modules
└── puppetlabs-vcsrepo (v0.0.4)
Install a module from a release archive:
$ puppet module install puppetlabs-vcsrepo-0.0.4.tar.gz
Preparing to install into /etc/puppetlabs/code/modules ...
Downloading from https://forgeapi.puppet.com ...
Installing -- do not interrupt ...
/etc/puppetlabs/code/modules
└── puppetlabs-vcsrepo (v0.0.4)
Install a module from a release archive and ignore dependencies:
$ puppet module install puppetlabs-vcsrepo-0.0.4.tar.gz --ignore-dependencies
Preparing to install into /etc/puppetlabs/code/modules ...
Installing -- do not interrupt ...
/etc/puppetlabs/code/modules
└── puppetlabs-vcsrepo (v0.0.4)
EOT
arguments _("<name>")
option "--force", "-f" do
summary _("Force overwrite of existing module, if any. (Implies --ignore-dependencies.)")
description <<-EOT
Force overwrite of existing module, if any.
Implies --ignore-dependencies.
EOT
end
option "--target-dir DIR", "-i DIR" do
summary _("The directory into which modules are installed.")
description <<-EOT
The directory into which modules are installed; defaults to the first
directory in the modulepath.
Specifying this option will change the installation directory, and
will use the existing modulepath when checking for dependencies. If
you wish to check a different set of directories for dependencies, you
must also use the `--environment` or `--modulepath` options.
EOT
end
option "--ignore-dependencies" do
summary _("Do not attempt to install dependencies. (Implied by --force.)")
description <<-EOT
Do not attempt to install dependencies. Implied by --force.
EOT
end
option "--version VER", "-v VER" do
summary _("Module version to install.")
description <<-EOT
Module version to install; can be an exact version or a requirement string,
eg '>= 1.0.3'. Defaults to latest version.
EOT
end
when_invoked do |name, options|
Puppet::ModuleTool.set_option_defaults options
Puppet.notice _("Preparing to install into %{dir} ...") % { dir: options[:target_dir] }
install_dir = Puppet::ModuleTool::InstallDirectory.new(Pathname.new(options[:target_dir]))
Puppet::ModuleTool::Applications::Installer.run(name, install_dir, options)
end
when_rendering :console do |return_value, name, _options|
case return_value[:result]
when :noop
Puppet.notice _("Module %{name} %{version} is already installed.") % { name: name, version: return_value[:version] }
exit 0
when :failure
Puppet.err(return_value[:error][:multiline])
exit 1
else
tree = Puppet::ModuleTool.build_tree(return_value[:graph], return_value[:install_dir])
"#{return_value[:install_dir]}\n" +
Puppet::ModuleTool.format_tree(tree)
end
end
end
end
|