2016-06-08 20:59:47 +00:00
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module Ansible
|
|
|
|
module Cap
|
|
|
|
module Guest
|
|
|
|
module Pip
|
|
|
|
|
ansible_local: Add the :pip_args_only install mode
With the introduction of `pip_args` option, you can easily extend the
`:pip` installation mode behaviour. But some interesting/advanced usages
are still not possible because of the auto-generated parts ("ansible"
package, version selection, and the `--upgrade` flag).
By adding this "pip_args_only" install mode, it will be for instance
possible to:
- install unofficial releases, like release candidates published at
https://releases.ansible.com/
- install more pip packages (e.g. via a `requirements.txt` file), with
hash validation, etc.
Note that there is no config validation that requires `pip_args` option
to be defined when the :pip_args_only mode is selected. This would be
more elegant, and user friendly to raise a configuration error, but this
can wait. At least, running with an empty `pip_args` won't lead to any
command crash, since the rather dummy "pip install" shows an helper
notice and terminates with a zero (0) exit code.
This change is thought as a complement to the changes originally
proposed in pull request GH-8170.
2017-03-23 22:10:56 +00:00
|
|
|
def self.pip_install(machine, package = "", version = "", pip_args = "", upgrade = true)
|
2017-03-23 07:16:45 +00:00
|
|
|
upgrade_arg = "--upgrade" if upgrade
|
2016-06-08 20:59:47 +00:00
|
|
|
version_arg = ""
|
|
|
|
|
|
|
|
if !version.to_s.empty? && version.to_s.to_sym != :latest
|
|
|
|
version_arg = "==#{version}"
|
|
|
|
end
|
|
|
|
|
2017-03-23 07:16:45 +00:00
|
|
|
args_array = [pip_args, upgrade_arg, "#{package}#{version_arg}"]
|
|
|
|
|
|
|
|
machine.communicate.sudo "pip install #{args_array.join(' ')}"
|
2016-06-08 20:59:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.get_pip(machine)
|
|
|
|
machine.ui.detail I18n.t("vagrant.provisioners.ansible.installing_pip")
|
|
|
|
machine.communicate.execute "curl https://bootstrap.pypa.io/get-pip.py | sudo python"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|