forked from ggiamarchi/vagrant-openstack-provider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support meta-args for shell provisioner
Fix ggiamarchi#205
- Loading branch information
1 parent
4cabf87
commit 4314fef
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'log4r' | ||
|
||
require 'vagrant/action/builder' | ||
|
||
require 'vagrant-openstack-provider/action/abstract_action' | ||
require 'vagrant-openstack-provider/action/read_ssh_info' | ||
|
||
module VagrantPlugins | ||
module Openstack | ||
module Action | ||
include Vagrant::Action::Builtin | ||
|
||
class ProvisionWrapper < AbstractAction | ||
def initialize(app, env) | ||
@app = app | ||
@env = env | ||
@logger = Log4r::Logger.new('vagrant_openstack::action::provision_wrapper') | ||
end | ||
|
||
def execute(env) | ||
@logger.info 'Run provisioning' | ||
InternalProvisionWrapper.new(@app, @env).call(@env) | ||
@app.call(env) | ||
end | ||
end | ||
|
||
class InternalProvisionWrapper < Vagrant::Action::Builtin::Provision | ||
def initialize(app, env) | ||
@logger = Log4r::Logger.new('vagrant_openstack::action::internal_provision_wrapper') | ||
super app, env | ||
end | ||
|
||
def run_provisioner(env) | ||
if env[:provisioner].class == VagrantPlugins::Shell::Provisioner | ||
handle_shell_meta_args(env) | ||
end | ||
env[:provisioner].provision | ||
end | ||
|
||
private | ||
|
||
def handle_shell_meta_args(env) | ||
config = env[:provisioner].config | ||
args = config.args.nil? ? [] : [config.args].flatten | ||
config.args = [] | ||
@logger.info "Shell provisioner args: #{args}" | ||
args.each do |arg| | ||
if '@@ssh_ip@@'.eql? arg | ||
ssh_info = VagrantPlugins::Openstack::Action.get_ssh_info(env) | ||
@logger.info "Replace meta-arg #{arg} by value #{ssh_info[:host]}" | ||
config.args << ssh_info[:host] | ||
else | ||
config.args << arg | ||
end | ||
end | ||
end | ||
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