Fix ansible install for older distributions

Before installing dependencies run a check for the python-dev-is-python3
package and only install it if found (otherwise use python-dev). This
allows older versions of debian (and derivatives) to properly install
the defined dependencies.
This commit is contained in:
Chris Roberts 2022-12-08 13:14:41 -08:00
parent 6fb60c9aea
commit ca7c05f09d
3 changed files with 38 additions and 7 deletions

View File

@ -37,12 +37,11 @@ INLINE_CRIPT
def self.pip_setup(machine, pip_install_cmd = "")
machine.communicate.sudo "apt-get update -y -qq"
debian_version = machine.communicate.execute "lsb_release -rs", error_check: false
if debian_version > 10
machine.communicate.sudo "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --option \"Dpkg::Options::=--force-confold\" build-essential curl git libssl-dev libffi-dev python-dev-is-python3"
else
machine.communicate.sudo "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --option \"Dpkg::Options::=--force-confold\" build-essential curl git libssl-dev libffi-dev"
python_dev_pkg = "python-dev"
if machine.communicate.test "apt-cache show python-dev-is-python3"
python_dev_pkg = "python-dev-is-python3"
end
machine.communicate.sudo "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --option \"Dpkg::Options::=--force-confold\" build-essential curl git libssl-dev libffi-dev #{python_dev_pkg}"
Pip::get_pip machine, pip_install_cmd
end

View File

@ -23,6 +23,7 @@ describe VagrantPlugins::Ansible::Cap::Guest::Debian::AnsibleInstall do
before do
allow(machine).to receive(:communicate).and_return(communicator)
allow(communicator).to receive(:execute).and_return(true)
allow(communicator).to receive(:test).and_return(false)
end
describe "#ansible_install" do

View File

@ -2,6 +2,8 @@
shared_examples_for "Ansible setup via pip" do
describe "when install_mode is :pip" do
before { allow(communicator).to receive(:test) }
it "installs pip and calls Cap::Guest::Pip::pip_install" do
expect(communicator).to receive(:sudo).at_least(1).times.ordered
expect(VagrantPlugins::Ansible::Cap::Guest::Pip).to receive(:pip_install).once.ordered.
@ -12,6 +14,8 @@ shared_examples_for "Ansible setup via pip" do
end
describe "when install_mode is :pip_args_only" do
before { allow(communicator).to receive(:test) }
it "installs pip and calls Cap::Guest::Pip::pip_install with 'pip_args' parameter" do
pip_args = "-r /vagrant/requirements.txt"
@ -27,8 +31,34 @@ end
shared_examples_for "Ansible setup via pip on Debian-based systems" do
describe "installs required Debian packages and..." do
before { allow(communicator).to receive(:test) }
pip_install_cmd = "foo"
it "calls Cap::Guest::Pip::get_pip with 'pip' install_mode" do
expect(communicator).to receive(:sudo).
with("apt-get update -y -qq")
expect(communicator).to receive(:sudo).
with("DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --option \"Dpkg::Options::=--force-confold\" build-essential curl git libssl-dev libffi-dev python-dev")
expect(communicator).to receive(:sudo).
with("pip install --upgrade ansible")
subject.ansible_install(machine, :pip, "", "", pip_install_cmd)
end
it "calls Cap::Guest::Pip::get_pip with 'pip_args_only' install_mode" do
expect(communicator).to receive(:sudo).
with("apt-get update -y -qq")
expect(communicator).to receive(:sudo).
with("DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --option \"Dpkg::Options::=--force-confold\" build-essential curl git libssl-dev libffi-dev python-dev")
expect(communicator).to receive(:sudo).
with("pip install")
subject.ansible_install(machine, :pip_args_only, "", "", pip_install_cmd)
end
context "when python-dev-is-python3 package is available" do
before { allow(communicator).to receive(:test).with("apt-cache show python-dev-is-python3").and_return(true) }
it "calls Cap::Guest::Pip::get_pip with 'pip' install_mode" do
expect(communicator).to receive(:sudo).
with("apt-get update -y -qq")
@ -50,6 +80,7 @@ shared_examples_for "Ansible setup via pip on Debian-based systems" do
subject.ansible_install(machine, :pip_args_only, "", "", pip_install_cmd)
end
end
end