-
-
Save ScottSturdivant/5707611 to your computer and use it in GitHub Desktop.
Fabric provisioner for Vagrant 1.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module VagrantPlugins | |
module Fabric | |
class Config < Vagrant.plugin("2", :config) | |
attr_accessor :fabfile_path | |
attr_accessor :fabric_path | |
attr_accessor :python_path | |
attr_accessor :tasks | |
def initialize | |
@fabfile_path = UNSET_VALUE | |
@fabric_path = UNSET_VALUE | |
@python_path = UNSET_VALUE | |
@tasks = UNSET_VALUE | |
end | |
def finalize! | |
@fabfile_path = "fabfile.py" if @fabfile_path == UNSET_VALUE | |
@fabric_path = "fab" if @fabric_path == UNSET_VALUE | |
@python_path = "python" if @python_path == UNSET_VALUE | |
@tasks = [] if @tasks == UNSET_VALUE | |
end | |
def validate(env) | |
errors = _detected_errors | |
if not File.exist?(fabfile_path) | |
errors << "No fabfile found." | |
end | |
which_fabric_path = `which #{fabric_path}` | |
if not $?.success? | |
errors << "fabric command does not exist." | |
end | |
which_python_path = `which #{python_path}` | |
if not $?.success? | |
errors << "python not found." | |
end | |
fabfile_package = fabfile_path.gsub(".py", "").gsub("/", ".") | |
output = `#{python_path} -c "exec 'import #{fabfile_package}'" &> /dev/null` | |
if not $?.success? | |
errors << "#{fabfile_package} could not import." | |
end | |
for task in tasks | |
task = task.split(":")[0] | |
package_path = "#{fabfile_package}.#{task}".gsub(".__init__", "") | |
packages = package_path.split(".") | |
output = `#{python_path} -c "exec 'from #{packages[0..-2].join('.')} import #{packages[-1]}'" > /dev/null 2>&1` | |
if not $?.success? | |
errors << "#{task} task does not exist." | |
end | |
end | |
{ "fabric provisioner" => errors } | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "vagrant" | |
module VagrantPlugins | |
module Fabric | |
class Plugin < Vagrant.plugin("2") | |
name "fabric" | |
config(:fabric, :provisioner) do | |
require File.expand_path("../config", __FILE__) | |
Config | |
end | |
provisioner(:fabric) do | |
require File.expand_path("../provisioner", __FILE__) | |
Provisioner | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module VagrantPlugins | |
module Fabric | |
class Provisioner < Vagrant.plugin("2", :provisioner) | |
def provision | |
ssh_info = machine.ssh_info | |
user = ssh_info[:username] | |
host = ssh_info[:host] | |
port = ssh_info[:port] | |
private_key = ssh_info[:private_key_path] | |
system "#{config.fabric_path} -i #{private_key} --config=#{config.fabfile_path} --user=#{user} --hosts=#{host} --port=#{port} #{config.tasks.join(' ')}" | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "plugins/provisioners/fabric/plugin.rb" | |
Vagrant.configure("2") do |config| | |
*snip* | |
config.vm.provision :fabric do |fab| | |
fab.tasks = ["setup_salt:kwarg=value"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have published the new version of vagrant-fabric plugin here (https://rubygems.org/gems/vagrant-fabric).
You can install it with just typing "vagrant plugin install vagrant-fabric".
And I changed my source code using your forked version.
Thank you for your contribution :)