From 19949301897ea0022a042185b97d4b4ccc65d083 Mon Sep 17 00:00:00 2001 From: Guillaume Giamarchi Date: Sun, 1 May 2016 00:23:20 +0200 Subject: [PATCH] Feature flip provisioner's meta-args Fix #248 Fix #249 --- README.md | 24 +++++++++++++++++++ .../lib/vagrant-openstack-provider/action.rb | 14 +++++++++-- .../lib/vagrant-openstack-provider/config.rb | 6 +++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1930474..c8222c7 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,30 @@ chef, and puppet) to work! * `http.open_timeout` - Open timeout for any HTTP request. Default is `60` * `http.read_timeout` - Read timeout for any HTTP request. Default is `30` +### Provisioners meta-args + +We call meta-args, dynamic arguments automatically injected by the vagrant OpenStack provider as +a provisioner argument. The notation for a meta-arg is its name surrounded by double `@` character. + +The current implementation supports only shell provisioner. + +* `meta_args_support` - Whether meta-args injection is activated or not. Default is `false` + +__Available meta-args__ + +* `@@ssh_ip@@` - The IP used by Vagrant to SSH into the machine + +__Usage example__ + +```ruby +config.vm.provision "shell", inline: 'echo "$1 : $2" > ~/provision', args: ['IP', '@@ssh_ip@@'] +``` + +__N.B.__ +> Activate meta-args support causes Vagrant to wrap the built-in provisioning middleware into a custom + one provided by the OpenStack provider. As a consequence, hooks declared on the built-in provisioning + middleware will not be applied (see [#248](https://github.com/ggiamarchi/vagrant-openstack-provider/issues/248)) + ## Vagrant standard configuration diff --git a/source/lib/vagrant-openstack-provider/action.rb b/source/lib/vagrant-openstack-provider/action.rb index 3068b49..42a9de2 100644 --- a/source/lib/vagrant-openstack-provider/action.rb +++ b/source/lib/vagrant-openstack-provider/action.rb @@ -34,7 +34,11 @@ def self.action_provision if env[:machine_state_id] == :not_created b2.use Message, I18n.t('vagrant_openstack.not_created') else - b2.use ProvisionWrapper + if env[:machine].provider_config.meta_args_support + b2.use ProvisionWrapper + else + b2.use Provision + end b2.use SyncFolders end end @@ -100,7 +104,13 @@ def self.action_up case env[:machine_state_id] when :not_created ssh_disabled = env[:machine].provider_config.ssh_disabled - b2.use ProvisionWrapper unless ssh_disabled + unless ssh_disabled + if env[:machine].provider_config.meta_args_support + b2.use ProvisionWrapper + else + b2.use Provision + end + end b2.use SyncFolders b2.use CreateStack b2.use CreateServer diff --git a/source/lib/vagrant-openstack-provider/config.rb b/source/lib/vagrant-openstack-provider/config.rb index 0847696..455e05e 100644 --- a/source/lib/vagrant-openstack-provider/config.rb +++ b/source/lib/vagrant-openstack-provider/config.rb @@ -195,6 +195,10 @@ class Config < Vagrant.plugin('2', :config) # @return [HttpConfig] attr_accessor :http + # + # @return [Boolean] + attr_accessor :meta_args_support + def initialize @password = UNSET_VALUE @openstack_compute_url = UNSET_VALUE @@ -236,6 +240,7 @@ def initialize @server_delete_timeout = UNSET_VALUE @stack_create_timeout = UNSET_VALUE @stack_delete_timeout = UNSET_VALUE + @meta_args_support = UNSET_VALUE @http = HttpConfig.new end @@ -320,6 +325,7 @@ def finalize! @server_delete_timeout = 200 if @server_delete_timeout == UNSET_VALUE @stack_create_timeout = 200 if @stack_create_timeout == UNSET_VALUE @stack_delete_timeout = 200 if @stack_delete_timeout == UNSET_VALUE + @meta_args_support = false if @meta_args_support == UNSET_VALUE @networks = nil if @networks.empty? @volumes = nil if @volumes.empty? @stacks = nil if @stacks.empty?