문제

I was trying to fix an issue in vagrant-rackspace plugin, which required running a command to remove the requiretty line from the sudoers file before the synced folder ran, as the rsync command would fail with sudo: sorry, you must have a tty to run sudo.

However, regardless of the order in the Vagrantfile, the synced folder action would always go first. It seems that in core Vagrant, the synced folder has the highest priority, and will always run first. I thought it would be like the provisioners, which are run in order they're put in the Vagrantfile.

도움이 되었습니까?

해결책

Eventually I remembered a similar looking line of code in a plugin I'd worked on recently:

 action_hook(:install_chef, Plugin::ALL_ACTIONS) do |hook|
    require_relative 'action/install_chef'
    hook.after(Vagrant::Action::Builtin::Provision, Action::InstallChef)

    if defined? VagrantPlugins::AWS::Action::TimedProvision
      hook.after(VagrantPlugins::AWS::Action::TimedProvision,
                 Action::InstallChef)
    end
  end

So, I just changed that to make sure the task I wanted always ran before the synced folder task:

  action_hook(:tty_workaround, Plugin::ALL_ACTIONS) do |hook|
     require_relative 'action/tty_workaround'
     hook.after(Vagrant::Action::Builtin::SyncedFolders, Action::TTYWorkaround)
  end

Worked like a charm!

I'm still trying to figure out if there's a way of doing this in Vagrant core, but for now I'm planning on making a vagrant plugin where you can give a path to a script you want to run on the vagrant node in the config, allowing you to use the above approach in any Vagrant instance, not just vagrant-rackspace.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top