Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action hook after provider specific actions #8500

Closed
fnordfish opened this issue Apr 20, 2017 · 5 comments
Closed

action hook after provider specific actions #8500

fnordfish opened this issue Apr 20, 2017 · 5 comments

Comments

@fnordfish
Copy link
Contributor

fnordfish commented Apr 20, 2017

Running on vagrant 1.9.3, I want a to inject a middleware at the very end of the stack. That is, after all provider specific actions and provisioning (if any) has run. In my specific case I want to make sure that all network stuff has been set up correctly. I also want to be provider agnostic, hence not injecting after something like VagrantPlugins::ProviderVirtualBox::Action::Network.

Here a compressed version of what I'm doing:

class MyMiddleware
  def initialize(app, env)
    @app = app
    @env = env
  end

  def call(env)
    @env = env
    env[:machine].ui.info "MyMiddleware called"
    @app.call(env)
  end
end

class MyPlugin < Vagrant.plugin("2")
  name "my-middleware-test"

  %w{up reload}.each do |action|
    action_hook(:my_middleware_test, "machine_action_#{action}".to_sym) do |hook|
      hook.append MyMiddleware
    end
  end
end

What I see is, that my middleware will get executed after, what I would call the default stack, but before provider specific actions:

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: testdrive_default_1492627978574_1277
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.2.0
    default: VirtualBox Version: 5.1
==> default: MyMiddleware called
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => <my_project>

Is there another hook I should use? (I've tried :machine_action_provision which does not work for me, since I also need to run when there is no provisioning)

fnordfish added a commit to BerlinVagrant/vagrant-dns that referenced this issue May 7, 2017
open issue: The `restart_host_dns` action hook needs to get moved after provider specific actions (so that the host network had a chance to get configured).
see hashicorp/vagrant#8500
@fnordfish
Copy link
Contributor Author

Any news here?

@fnordfish
Copy link
Contributor Author

Hi again.
Is this something I could do with vagrant 2.1's triggers?
Could I, as a plugin, try to hijack the vm's config and inject a trigger-config which calls back to me? Of cause, the plugin could also just provide a public interface and let the user write their own trigger config.

/cc @briancain @chrisroberts

@chrisroberts chrisroberts added this to the 2.1 milestone May 7, 2018
@little-dude
Copy link

I'm also interested in that. Unlike OP I could use machine_action_provision but it does not seems to work with Vagrant 2.1.1.

@briancain
Copy link
Member

Hey there, this will be in the next release of Vagrant via #10615. Cheers! 🎉

@ghost
Copy link

ghost commented Mar 28, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants