Skip to content

Commit

Permalink
Feature flip provisioner's meta-args
Browse files Browse the repository at this point in the history
Fix #248
  • Loading branch information
ggiamarchi committed Apr 30, 2016
1 parent 4bfa06a commit 0ca4e4b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 12 additions & 2 deletions source/lib/vagrant-openstack-provider/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions source/lib/vagrant-openstack-provider/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit 0ca4e4b

Please sign in to comment.