Merge pull request #11411 from thunder-spb/alpine-ansbile-support
Alpine capability for Ansbile support
This commit is contained in:
commit
dda2c8f913
@ -0,0 +1,44 @@
|
||||
require_relative "../facts"
|
||||
require_relative "../pip/pip"
|
||||
|
||||
module VagrantPlugins
|
||||
module Ansible
|
||||
module Cap
|
||||
module Guest
|
||||
module Alpine
|
||||
module AnsibleInstall
|
||||
|
||||
def self.ansible_install(machine, install_mode, ansible_version, pip_args, pip_install_cmd = "")
|
||||
case install_mode
|
||||
when :pip
|
||||
pip_setup machine, pip_install_cmd
|
||||
Pip::pip_install machine, "ansible", ansible_version, pip_args, true
|
||||
when :pip_args_only
|
||||
pip_setup machine, pip_install_cmd
|
||||
Pip::pip_install machine, "", "", pip_args, false
|
||||
else
|
||||
ansible_apk_install machine
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.ansible_apk_install(machine)
|
||||
machine.communicate.sudo "apk add --update --no-cache python3 ansible"
|
||||
machine.communicate.sudo "if [ ! -e /usr/bin/python ]; then ln -sf python3 /usr/bin/python ; fi"
|
||||
machine.communicate.sudo "if [ ! -e /usr/bin/pip ]; then ln -sf pip3 /usr/bin/pip ; fi"
|
||||
end
|
||||
|
||||
def self.pip_setup(machine, pip_install_cmd = "")
|
||||
machine.communicate.sudo "apk add --update --no-cache python3"
|
||||
machine.communicate.sudo "if [ ! -e /usr/bin/python ]; then ln -sf python3 /usr/bin/python ; fi"
|
||||
machine.communicate.sudo "apk add --update --no-cache --virtual .build-deps python3-dev libffi-dev openssl-dev build-base"
|
||||
Pip::get_pip machine, pip_install_cmd
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -45,6 +45,11 @@ module VagrantPlugins
|
||||
Cap::Guest::Arch::AnsibleInstall
|
||||
end
|
||||
|
||||
guest_capability(:alpine, :ansible_install) do
|
||||
require_relative "cap/guest/alpine/ansible_install"
|
||||
Cap::Guest::Alpine::AnsibleInstall
|
||||
end
|
||||
|
||||
guest_capability(:debian, :ansible_install) do
|
||||
require_relative "cap/guest/debian/ansible_install"
|
||||
Cap::Guest::Debian::AnsibleInstall
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
require_relative "../../../../../../base"
|
||||
require_relative "../shared/pip_ansible_install_examples"
|
||||
|
||||
require Vagrant.source_root.join("plugins/provisioners/ansible/cap/guest/alpine/ansible_install")
|
||||
|
||||
describe VagrantPlugins::Ansible::Cap::Guest::Alpine::AnsibleInstall do
|
||||
include_context "unit"
|
||||
|
||||
subject { VagrantPlugins::Ansible::Cap::Guest::Alpine::AnsibleInstall }
|
||||
|
||||
let(:iso_env) do
|
||||
# We have to create a Vagrantfile so there is a root path
|
||||
env = isolated_environment
|
||||
env.vagrantfile("")
|
||||
env.create_vagrant_env
|
||||
end
|
||||
|
||||
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
|
||||
let(:communicator) { double("comm") }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
allow(communicator).to receive(:execute).and_return(true)
|
||||
end
|
||||
|
||||
describe "#pip_setup" do
|
||||
it "install required alpine packages for pip" do
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("apk add --update --no-cache python3")
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("if [ ! -e /usr/bin/python ]; then ln -sf python3 /usr/bin/python ; fi")
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("apk add --update --no-cache --virtual .build-deps python3-dev libffi-dev openssl-dev build-base")
|
||||
|
||||
subject.pip_setup(machine)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#ansible_install" do
|
||||
|
||||
it_behaves_like "Ansible setup via pip"
|
||||
|
||||
describe "when install_mode is :default (or unknown)" do
|
||||
it "installs ansible with 'apk' package manager" do
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("apk add --update --no-cache python3 ansible")
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("if [ ! -e /usr/bin/python ]; then ln -sf python3 /usr/bin/python ; fi")
|
||||
expect(communicator).to receive(:sudo).once.ordered.
|
||||
with("if [ ! -e /usr/bin/pip ]; then ln -sf pip3 /usr/bin/pip ; fi")
|
||||
|
||||
subject.ansible_install(machine, :default, "", "", "")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user