Coder Social home page Coder Social logo

vagrant-triggers's People

Contributors

bitdeli-chef avatar brethash avatar emyl avatar fonsecas72 avatar jperville avatar msabramo avatar nickrw avatar paulcdejean avatar voxik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vagrant-triggers's Issues

Triggers not running for vagrant rsync

I can't seem to write a trigger that runs for the rsync command.

This works (displays a message on the console):

config.trigger.before :suspend do
    error "This works"
end

This doesn't do anything (no message on the console):

config.trigger.before :rsync do
    error "This does nothing"
end

It would be very nice to be able to run triggers for the rsync and rsync-auto actions.

Support non buffered command output

First of all, great work! Valuable plugin which I cannot live without for all my vagrant setups!

That said, I think that supporting interactive commands would be a great feature to add to this. It would allow, for example, to automatically install dependencies on the host OS in case they're missing. This is just one usage scenario, but I'm sure it would be useful for many more things.
No idea if it's a pain to implement or not, so apologies if it's too much to ask for :)

"run" Command Hangs When Subprocess Waits For User Input

I have a Vagrantfile that contains the following:

config.vm.provision "trigger" do |trigger|
    trigger.fire do
        run "read"
    end
end

When I run vagrant provision it waits for input forever even when I type and hit enter.

If I use Ruby's system command instead, everything works as expected:

config.vm.provision "trigger" do |trigger|
    trigger.fire do
        system("read")
    end
end

Tested with vagrant-triggers 0.5.2

trigger / provisioning order

Is the intention for initial ":up" and ":provision" after scripts to run before the provisioning takes place? On my intended Vagrantfile and on the simplest Vagrantfile possible this order makes it impossible to let ":shell" provisioning happen before the after script.

virtualbox 4.3.12
vagrant 1.6.2
vagrant-triggers 0.4.0

My Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"

config.vm.provision :shell do |shell|
shell.path = "provision.sh"
end

config.trigger.before :up, :stdout => true do
print "Before up!\n"
end

config.trigger.after :up, :stdout => true do
print "After up!\n"
end

config.trigger.after :provision, :stdout => true do
print "After provision!\n"
end

end

Vagrant 1.7.3 subprocess jail can break execution of ruby commands

I just noticed, that starting with Vagrant 1.7.3 the execution of ruby commands via the vagrant-triggers plugin (and possibly all exeution of external ruby commands) is broken.

When calling a command via vagrant-triggers run, vagrant-triggers takes care to delete GEM_HOME, GEM_PATH and GEMRC from the environment (in https://github.com/emyl/vagrant-triggers/blob/master/lib/vagrant-triggers/dsl.rb#L87), so we can execute ruby commands, that depend on a non vagrant ruby environment.

But vagrant introduced a new "magic" to check if it is executed via bundler, and restores the vagrant environment for the subprocess. So if you call a ruby process, vagrant enforces the old environment and GEM_HOME, GEM_PATH and GEMRC point to the vagrant specific gem locations and things break because gems are not found.

We can set VAGRANT_SKIP_SUBPROCESS_JAILBREAK environment variable to disable the magic, but we need to set it before calling vagrant. Setting it in the Vagrantfile does not seem to work.

https://docs.vagrantup.com/v2/other/environmental-variables.html

VAGRANT_SKIP_SUBPROCESS_JAILBREAK

As of Vagrant 1.7.3, Vagrant tries to intelligently detect if it is running in the installer or running via Bundler. Although not officially supported, Vagrant tries its best to work when executed via Bundler. When Vagrant detects that you have spawned a subprocess that lives outside of Vagrant's installer, Vagrant will do its best to reset the preserved environment dring the subprocess execution.

If Vagrant detects it is running outside of the officially installer, the original environment will always be restored. You can disable this automatic jailbreak by setting the VAGRANT_SKIP_SUBPROCES_JAILBREAK.

I am not sure, how to work around this or how to switch off this behaviour from within the Vagrantfile. It was introduced in Vagrant 1.7.3 (a minor release) and breaks stuff that worked with 1.7.2.

This is not a vagrant-triggers bug, I opened a vagrant bug: hashicorp/vagrant#6242

But maybe @emyl can think of a workaround to make vagrant-triggers with ruby commands work again.

Whitelist for command return codes

It would be nice if there was an option to whitelist command return codes to mark them as non-fatal errors.

Think of a trigger which mounts a Samba share from the Vagrant machine. On the first run of the first machine, this will work fine. But on subsequent runs (machine stopped & restarted / another machine started) this command will output an error along the lines of share already mounted, which is not an error per se but will confuse users.

If the return code of that error (e.g. 2 instead of 0 for gvfs-mount and 85 for net) was whitelisted, no error message would be outputted and trigger execution would continue as usual.

After triggered script wtih vagrant up

Thank you for an awesome plugin.

When I use the following configuration my command is never run after the up command. If I use config.trigger.before the command is run before up but this is to early in my case. All the other commands are run with the after trigger so I am not sure what is wrong here.

{[:up, :resume, :reload, :provision] => "./mount.sh",}.each do |command, trigger|
config.trigger.after command, :execute => "#{trigger}", :stdout => true
end

ERROR: Failed to build gem native extension.

Hello everyone.

I have done the following steps:

  • I installed Vagrant from scratch by following all procedures to perform the job properly. Vagrant work.
  • I tried to install the plugin vagrant-triggers but get the following error:
Installing the 'vagrant-triggers' plugin. This can take a few minutes...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:

An error occurred while installing ffi (1.9.7), and Bundler cannot continue.
Make sure that `gem install ffi -v '1.9.7'` succeeds before bundling.

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

...

(More text below)
  • I further tried to re-install Vagrant but without any success.

There is an additional text-log, next to the error mentioned but I avoid writing it because it is very long. If required I can post it.

Here are the details of my host system:

  • OS: Windows 7 ultimate
  • Vagrant 1.7.2

Is there a way to get a better result?

Best regards.

Passing an array of strings to the vm argument does not work

The documentation states that the :vm parameter can be a string, a regex, or an array of strings and/or regex, but when I pass an array of strings, I get this error:

/home/antonio/.vagrant.d/gems/gems/vagrant-triggers-0.4.2/lib/vagrant-triggers/action/trigger.rb:42:in `match': type mismatch: String given (TypeError)
        from /home/antonio/.vagrant.d/gems/gems/vagrant-triggers-0.4.2/lib/vagrant-triggers/action/trigger.rb:42:in `block (3 levels) in fire_triggers'
        from /home/antonio/.vagrant.d/gems/gems/vagrant-triggers-0.4.2/lib/vagrant-triggers/action/trigger.rb:41:in `each'
        from /home/antonio/.vagrant.d/gems/gems/vagrant-triggers-0.4.2/lib/vagrant-triggers/action/trigger.rb:41:in `block (2 levels) in fire_triggers'
        from /home/antonio/.vagrant.d/gems/gems/vagrant-triggers-0.4.2/lib/vagrant-triggers/action/trigger.rb:35:in `each'
        from /home/antonio/.vagrant.d/gems/gems/vagrant-triggers-0.4.2/lib/vagrant-triggers/action/trigger.rb:35:in `block in fire_triggers'
        from /home/antonio/.vagrant.d/gems/gems/vagrant-triggers-0.4.2/lib/vagrant-triggers/action/trigger.rb:34:in `tap'
        from /home/antonio/.vagrant.d/gems/gems/vagrant-triggers-0.4.2/lib/vagrant-triggers/action/trigger.rb:34:in `fire_triggers'
        from /home/antonio/.vagrant.d/gems/gems/vagrant-triggers-0.4.2/lib/vagrant-triggers/action/trigger.rb:16:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/warden.rb:34:in `call'
        from /home/antonio/.vagrant.d/gems/gems/vagrant-triggers-0.4.2/lib/vagrant-triggers/action/trigger.rb:17:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/warden.rb:34:in `call'
        from /home/antonio/.vagrant.d/gems/gems/vagrant-triggers-0.4.2/lib/vagrant-triggers/action/trigger.rb:17:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/warden.rb:34:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/builder.rb:116:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/runner.rb:66:in `block in run'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/util/busy.rb:19:in `busy'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/runner.rb:66:in `run'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/machine.rb:196:in `action_raw'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/machine.rb:173:in `block in action'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/environment.rb:474:in `lock'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/machine.rb:161:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/machine.rb:161:in `action'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/plugins/commands/destroy/command.rb:31:in `block in execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/plugin/v2/command.rb:226:in `block in with_target_vms'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/plugin/v2/command.rb:220:in `each'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/plugin/v2/command.rb:220:in `with_target_vms'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/plugins/commands/destroy/command.rb:30:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/cli.rb:42:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/environment.rb:292:in `cli'
        from /opt/vagrant/bin/../embedded/gems/gems/vagrant-1.6.5/bin/vagrant:174:in `<main>'

If I pass a regex that matches the same strings I passed, it works.

"Invalid Unicode Property \P" on windows

D:/VagrantHome/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/dsl.rb:90: warning: invalid Unicode Property \P: /D:\Programs\HashiCorp\Vagrant\embedded.*?;/

Destroy trigger fired before confirmation

I defined a destroy trigger like this:

    config.trigger.before :destroy, :stdout => true, :stderr => true do
        run_remote "/vagrant/cleanup.sh"
    end

This leads to cleanup.sh being called right before confirmation.

Do you see any way to get the trigger called only if confirmation is given or --force is used?

Not able to use commands with wildcards on arguments

Hi there,

I'm not being able to execute commands containing a wildcard. For instance:

  config.trigger.after :halt do
    run "ls app/logs/"
  end

Works just fine... but:

  config.trigger.after :halt do
    run "ls app/logs/*"
  end

Does not work. I generates the following output:

==> default: Running triggers after halt...
==> default: Executing command "ls app/logs/*"...
==> default: /bin/ls: cannot access app/logs/*: No such file or directory
==> default: Command execution finished.
The command "ls app/logs/*" returned a failed exit code. The
error output is shown below:

/bin/ls: cannot access app/logs/*: No such file or directory

On the command line it works fine though.

Any ideas?

BTW, I'm using version 0.5.2

PS- I get the same error for the rm command as well.

run script in between commands in a multi-machine environment

Does this plugin handle the situation where, in a multi-machine environment, if I bring up 2 machines with vagrant up, i can execute commands in between bringing the two machines up?

For example:
Assuming a 2 machine setup when vagrant up is executed:

execute script
machine 1 starts up
execute script
machine 2 starts up

:stderr, :stdout defaults to false when using config.vm.provision "trigger"

Hi,

first of all, thanks for the great plugin!

The documentation states:

  • :stderr => true|false: display standard error from scripts. Defaults to true.
  • :stdout => true|false: display standard output from scripts. Defaults to true.

I'm using the following setup:

  config.vm.provision "trigger" do |trigger|
    trigger.fire do
      run "uname -a"
    end 
  end 

I got no output at all unless explicitly setting the options stdout and/or stderr to true:

  config.vm.provision "trigger", :stdout => true, :stderr => true do |trigger|

Vagrant 1.7.2
vagrant-triggers 0.5.0

Does the documentation need an update or is this a bug?

Another example to add please

Hi @emyl . Thanks for the awesome plugin. It's really very helpful.

I'm not a Ruby guy, so like a lot of other people here, examples are good. In my specific situation, writing a config.trigger.before :provision block only triggers when I run vagrant provision. I'd really like that block to hit when I run any of

  • vagrant provision
  • vagrant up --provision
  • the first vagrant up when the provision step us run
  • if any config.vm.provision block is set to run: "always"

Is there something straight-forward I can do to make this happen?

Execution of ruby script fails because of missing gems

Thanks for this fantastic plugin.

I have a project with a thor script in ./bin/command.

From my command line, it works fine:

$ ./bin/command delete_cert -h ml
Running command: sudo find /data/puppet/var/ssl/ca/signed -regextype  posix-egrep -regex '.*/ml\.local\.pem' -print -delete

on host: puppetmaster

If I invoke this from a hook, it fails:

cfg.trigger.after :destroy, :execute => "./bin/command delete_cert -h ml", :stdout => true
$ vagrant destroy ml
Are you sure you want to destroy the 'ml' VM? [y/N] y
[ml] Forcing shutdown of VM...
[ml] Destroying VM and associated drives...
[ml] Running cleanup tasks for 'shell' provisioner...
[ml] Running triggers after action...
[ml] Executing command "./bin/command delete_cert -h ml"...
The command "./bin/command delete_cert -h ml" returned a failed exit code. The
error output is shown below:

/Applications/Vagrant/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in `require': cannot load such file -- thor (LoadError)
    from /Applications/Vagrant/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in `require'
    from ./bin/command:3:in `<main>'

It seems to be executing the script in the context of the embedded Vagrant ruby, rather than invoking as a regular script using the system ruby + gems. Any ideas?

Execute specific provisioner after trigger

Hi,

I want to use your module to override "vagrant destroy".

This actually works like a charm, but now I've wrote a special puppet uninstall manifest to ensure that some files are being deleted from my machine.
Is there any way of doing that?

I am using puppet already for provisioning, as I've read, there is a way to override the manifest file in that provisioner configuration. So my goal is, catching vagrant destroy, change the manifest to my uninstall one and running the provisioner after that.

Any suggestions?

Trigger for "box update"

Is it possible to hook into the various "box" commands? We would like to have a trigger for vagrant box update, but that doesn't seem to be possible.

Clean Up when "Vagrant Destroying" Specific Machine in Multi-Machine Vagrantfile

Say I've got a multi-machine Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  unless Vagrant.has_plugin?("vagrant-triggers")
    raise 'vagrant-triggers plugin needs to be installed: vagrant plugin install vagrant-triggers'
  end

  host_script_dir = "./scripts"
  vm_script_dir = "/vagrant/scripts"

  host_provisioned_dir = "#{host_temp_dir}/provisioned"
  vm_provisioned_dir = "#{vm_temp_dir}/provisioned"

  config.vm.define "db" do |v|

    # do stuff

  end

  config.vm.define "web" do |v|

    # do stuff

  end

  config.trigger.after :destroy, :stdout => true, :force => true do
    # this is too coarse of a provisioning step. for instance, 
    # maybe i want to remove a specific subdirectory when i 
    # destroy the "web" machine
    info "Removing provisioned directory contents: #{host_provisioned_dir}/*"
    FileUtils.rm_rf Dir.glob("#{host_provisioned_dir}/*")
  end

end

Is there a way to tie the cleanup to the machine being destroyed?

run command does not properly handle passed quotes

OS Centos 6
INFO global: Vagrant version: 1.7.2
INFO global: Ruby version: 2.0.0
INFO global: RubyGems version: 2.0.14
INFO global: - vagrant-triggers = 0.5.0

So I have a problem with passing quotes within quotes while using vagrant-triggers.

Essentially I'm trying to run this sed command, which works fine on the command line:
sed -i -r 's/"groups": [$/"groups": [\n "TEST_admin",/' ~/chef-repo/data_bags/users/vagrant.json

Normally that would be:
run "sed -i -r 's/"groups": [$/"groups": [\n "TEST_admin",/' ~/chef-repo/data_bags/users/vagrant.json"

The quotes being processed on three different levels (vagrant-triggers, command line and regular expression) causes a problem. Using ruby variables I've eliminated one level of the problem now I only have to deal with vagrant-triggers (ruby) and command line. I can theoretically backslash a quote to fix that problem.

   #Before we do anything with this box:
   config.trigger.before :up do
    admimquote = '"TEST_admin"'
    groupquote = '"groups"'
    run  "sed -i -r \'s/#{groupquote}: \\[$/#{groupquote}: \\[\\n    #{admimquote},/\' ~/chef-repo/data_bags/users/vagrant.json"
   end

The reason I'm logging this as a possible bug ticket is that I'm getting back two responses from the logging and I can't tell which one its outputted to the command line.

"INFO interface:" indicates its executing this command:
sed -i -r s/"groups": [$/"groups": [n "TEST_admin",/ ~/chef-repo/data_bags/users/vagrant.json

The "ERROR warden:" is indicating it received this command:
sed -i -r 's/"groups": [$/"groups": [\n "TEST_admin",/' ~/chef-repo/data_bags/users/vagrant.json

I can't tell from the logs which command was actually sent to the command line.

Here is the full error:

 INFO interface: info: Executing command "sed -i -r s/"groups": [$/"groups": [n    "TEST_admin",/ ~/chef-repo/data_bags/users/vagrant.json"...
 INFO interface: info: ==> default: Executing command "sed -i -r s/"groups": [$/"groups": [n    "TEST_admin",/ ~/chef-repo/data_bags/users/vagrant.json"...
==> default: Executing command "sed -i -r s/"groups": [$/"groups": [n    "TEST_admin",/ ~/chef-repo/data_bags/users/vagrant.json"...
 INFO subprocess: Starting process: ["/bin/sed", "-i", "-r", "s/\"groups\": [$/\"groups\": [n    \"TEST_admin\",/", "~/chef-repo/data_bags/users/vagrant.json"]
 INFO interface: error: /bin/sed: -e expression #1, char 47: unterminated `s' command

 INFO interface: error: ==> default: /bin/sed: -e expression #1, char 47: unterminated `s' command
==> default: /bin/sed: -e expression #1, char 47: unterminated `s' command
 INFO interface: info: Command execution finished.
 INFO interface: info: ==> default: Command execution finished.
==> default: Command execution finished.
ERROR warden: Error occurred: The command "sed -i -r 's/"groups": \[$/"groups": \[\n    "TEST_admin",/' ~/chef-repo/data_bags/users/vagrant.json" returned a failed exit code. The
error output is shown below:

/bin/sed: -e expression #1, char 47: unterminated `s' command

For testing hereโ€™s the pertinent portion of vagrant.json that sed is working on the sed command should add a line between groups and lastentry:

  "groups": [
    "lastentry"
  ],

How to triggers a command after rsync-auto

How to trigger a command after rsync-auto

$vagrant rsync-auto

I'm looking for the below vagrant dsl to execute whenever there happens an rsync between host to guest.

But the below script is not working !!

config.trigger.after :rsync do
        run "pwd"
  end

Cannot use builtin commands (e.g. "if") on Windows hosts

To reduce the noise when trying to re-mount an existing share drive (see #27), I'd like to make it conditional. This is what I tried:

config.trigger.after :up do
  # Mount network share after startup
  run "if not exist Z: net use /y Z: \\\\192.168.33.10\\webroot"
end

This yields the following error:

The executable "if" Vagrant is trying to trigger
was not found. If you know it is not in the PATH, please
specify its absolute path using the :append_to_path option.

Sure, if is no command (executable) but a builtin. Thus I tried with a sub-process:

config.trigger.after :up do
  # Mount network share after startup
  run 'cmd /c "if not exist Z: net use /y Z: \\\\192.168.33.10\\webroot"'
end

But this gives me the following error:

The command "cmd /c "if not exist Z: net use /y Z: \192.168.33.10\webroot"" returned a failed exit
code. The error output is shown below:
Syntax error.

Executing cmd /c "if not exist Z: net use /y Z: \\192.168.33.10\webroot" within a command prompt works perfectly fine though.

Any idea what's wrong here?

Trigger before :provision is not called during first up.

The following Vagrantfile does not create the expected tmp/file.txt in the working directory on first startup using version 0.5.0.

if !Vagrant.has_plugin?("vagrant-triggers")
    puts "'vagrant-triggers' plugin is required"
    puts "This can be installed by running:"
    puts
    puts " vagrant plugin install vagrant-triggers"
    puts
    exit
end

Vagrant.configure(2) do |config|
    config.trigger.before :provision do
        info "Creating temporary file"

        run "mkdir -p tmp"
        run 'touch tmp/file.txt'
    end

    config.vm.define "Device" do |device|
        device.vm.box = "ubuntu/trusty64"
    end
end

Best regards

Using :force => true does not handle remote_run failing to connect to the node

When using the following trigger:

config.trigger.before :destroy, :vm => vm_name, :force => true, :stdout => false, :stderr => false do
        run_remote "/usr/bin/docker exec postgres /bin/bash -c \"su postgres -c '/usr/pgsql-9.4/bin/pg_ctl stop -m fast -D /var/lib/postgres'\""
end

If the VM happens to not be running during a destroy the destroy process fails because the run_remote cannot connect to the node. Is there something I am missing here? Is there anyway to only run the command if the node is actively running?

Exception:

==> core02: Running triggers before destroy...
==> core02: Executing remote command "/usr/bin/docker exec postgres /bin/bash -c "su postgres -c '/usr/pgsql-9.4/bin/pg_ctl stop -m fast -D /var/lib/postgres'""...
The provider for this Vagrant-managed machine is reporting that it
is not yet ready for SSH. Depending on your provider this can carry
different meanings. Make sure your machine is created and running and
try again. Additionally, check the output of `vagrant status` to verify
that the machine is in the state that you expect. If you continue to
get this error message, please view the documentation for the provider
you're using.

Installation

Hi!

Is it supposed to require me to install nokogiri before?
I tried just installing it as in the instructions (running vagrant 1.6.x) but get the error that I require nokogiri..
Unfortunately that leads me to a spiral of installs like honeybrew, libxml2 etc. etc. which is a road I'd prefer not to have to go down :)

I'm no a poweruser in anyway, I enjoy vagrant with varying vagrants vagrant for my wordpress development, that's about it!

Thanks!

Current working directory of triggered script is not the location of the Vagrantfile

Vagrant allows you to run "vagrant ..." from any directory, and it will search upwards to find the nearest Vagrantfile. I've written my trigger scripts assuming that the current working directory is the same directory as my Vagrantfile, but that appears to not be the case. Here's my workaround:

  config.trigger.before [:reload, :up, :provision], stdout: true do
    Dir.chdir '..' while !File.exist?('Vagrantfile')
    ...
  end

vagrant installs plugin without errors, but cant list it

Hi,

Running Vagrant 1.7.2 here .. on Debian wheezy x64

vagrant plugin install vagrant-triggers runs Ok

$ vagrant plugin install vagrant-triggers --verbose
Installing the 'vagrant-triggers' plugin. This can take a few minutes...
Fetching source index from http://gems.hashicorp.com/
Fetching gem metadata from https://rubygems.org/.........
Fetching additional metadata from https://rubygems.org/..........
Resolving dependencies...
Using builder 3.2.2
Using gyoku 1.2.2
Using mini_portile 0.6.0
Using nokogiri 1.6.3.1
Using akami 1.2.2
Using bundler 1.7.11
Using hitimes 1.2.2
Using timers 4.0.1
Using celluloid 0.16.0
Using ffi 1.9.8
Using childprocess 0.5.6
Using erubis 2.7.0
Using gssapi 1.0.3
Using hashicorp-checkpoint 0.1.4
Using httpclient 2.6.0.1
Using rack 1.6.0
Using httpi 0.9.7
Using i18n 0.6.11
Using json 1.8.2
Using rb-fsevent 0.9.4
Using rb-inotify 0.9.5
Using listen 2.8.4
Using little-plugger 1.1.3
Using log4r 1.1.10
Using multi_json 1.11.0
Using logging 1.8.2
Using mime-types 1.25.1
Using net-ssh 2.9.2
Using net-scp 1.1.2
Using net-sftp 2.1.2
Using nori 1.1.5
Using rb-kqueue 0.2.3
Using rdoc 4.2.0
Using rest-client 1.6.8
Using rubyntlm 0.1.1
Using wasabi 1.0.0
Using savon 0.9.5
Using uuidtools 2.1.5
Using wdm 0.1.0
Using winrm 1.1.3
Using vagrant 1.7.2
Using vagrant-share 1.1.3
Installing vagrant-triggers 0.5.0
Installed the plugin 'vagrant-triggers (0.5.0)'!

But then vagrant plugin list would not display vagrant-triggers as an installed plugin .. and other tools that try to use the plugin fail, because as far as vagrant is concerned the plugin is not installed ..

Is this a vagrant version issue ? What could be the problem here?

Nokogiri?

Hi,

Thanks for the plugin. I am using MacOSX Yosemite and cannot get the vagrant-triggers plugin to install. I am using Boot2Docker, of course.

I have installed nokogiri successfully on the Mac but when I try to install the plugin it gives me an error suggesting it is not installed:

An error occurred while installing nokogiri (1.6.6.2), and Bundler cannot continue.
Make sure that gem install nokogiri -v '1.6.6.2' succeeds before bundling.

As mentioned, it is installed
$ nokogiri -v

Nokogiri (1.6.6.2)


---
warnings: []
nokogiri: 1.6.6.2
ruby:
  version: 2.0.0
  platform: universal.x86_64-darwin14
  description: ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
  engine: ruby
libxml:
  binding: extension
  source: packaged
  libxml2_path: /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2/ports/x86_64-apple-darwin14/libxml2/2.9.2
  libxslt_path: /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2/ports/x86_64-apple-darwin14/libxslt/1.1.28
  libxml2_patches:
  - 0001-Revert-Missing-initialization-for-the-catalog-module.patch
  - 0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch
  libxslt_patches:
  - 0001-Adding-doc-update-related-to-1.1.28.patch
  - 0002-Fix-a-couple-of-places-where-f-printf-parameters-wer.patch
  - 0003-Initialize-pseudo-random-number-generator-with-curre.patch
  - 0004-EXSLT-function-str-replace-is-broken-as-is.patch
  - 0006-Fix-str-padding-to-work-with-UTF-8-strings.patch
  - 0007-Separate-function-for-predicate-matching-in-patterns.patch
  - 0008-Fix-direct-pattern-matching.patch
  - 0009-Fix-certain-patterns-with-predicates.patch
  - 0010-Fix-handling-of-UTF-8-strings-in-EXSLT-crypto-module.patch
  - 0013-Memory-leak-in-xsltCompileIdKeyPattern-error-path.patch
  - 0014-Fix-for-bug-436589.patch
  - 0015-Fix-mkdir-for-mingw.patch
  compiled: 2.9.2
  loaded: 2.9.2

Will this plugin work with boot2docker?

What do I need to do?

Thanks in advance for any suggestions.

Cheers,
Ashley.

PS I was thinking it needs to be installed in the VM, but gem isn't even installed on the VM so I could not just install nokogiri.

Run Cookbooks On Up?

Hi,

I was curious if it is possible to run specific cookbooks on a vagrant up. These would be tasks that are required to run every time a machine is brought up, not just on a provision.

More Examples Please

I'm having trouble doing some simple things, both because I'm a Ruby noob, and because I can find only two vagrant-triggers examples on the internet (and their syntaxes seem to conflict).

Could you provide an example for, say:

  • Running a command, with options, on the host after "vagrant destroy." It could be something simple, like running ls -al.
  • Also, is it possible to run inline Ruby with a trigger? An example of that would also be useful.

run_remote fails

Running into an issue where run_remote will not work because of a lock issue with vagrant and the vm. I read that this was resolved in/after 1.6.2, but it looks like it is still happening to me. Just wondering if you have seen this since or what the work around if for it?

Vagrant version:

$ vagrant --version
Vagrant 1.6.3

Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define :devbox do |devbox|
    [ ... ] # config here
    devbox.trigger.after [:up, :resume, :reload], :stdout => true do
      info "Restarting apache on vm"
      run_remote "sudo service apache2 restart"
    end
  end
end

Output:

$ vagrant reload
...
==> devbox: Running triggers after reload...
==> devbox: Restarting apache on vm
==> devbox: Executing command "vagrant ssh -c 'sudo service apache2 restart' devbox"...
The command "vagrant ssh -c 'sudo service apache2 restart' devbox" returned a failed exit code. The
error output is shown below:

An action 'read_state' was attempted on the machine 'devbox',
but another process is already executing an action on the machine.
Vagrant locks each machine for access by only one process at a time.
Please wait until the other Vagrant process finishes modifying this
machine, then try again.

If you believe this message is in error, please check the process
listing for any "ruby" or "vagrant" processes and kill them. Then
try again.

global triggers

How difficult would it be to introduce the notion of a "global" trigger for use in multi-machine environments? That is, a trigger which would fire once for all machines rather than once for each machine. I'm thinking here of the use case of cluster-wide setup/cleanup operations.

Eg. In an aws ec2 env I'd like to dynamically allocate a subnet for my cluster as a "before" action upon 'vagrant up' and dealloc as an "after" action upon 'vagrant destroy' - one operation for all machines.

run bug

I seems to be having a slight issue when trying to run any code using this plugin. It used to work fine for me, but now I get this error every time:

/home/pete/.vagrant.d/gems/gems/vagrant-triggers-0.4.3/lib/vagrant-triggers/dsl.rb:25:in `run': uninitialized constant VagrantPlugins::Triggers::DSL::Bundler (NameError)
    from /var/www/git-repository/newint-agile/newint_vagrant/Vagrantfile:173:in `block (2 levels) in <top (required)>'
    from /home/pete/.vagrant.d/gems/gems/vagrant-triggers-0.4.3/lib/vagrant-triggers/action/trigger.rb:59:in `instance_eval'
    from /home/pete/.vagrant.d/gems/gems/vagrant-triggers-0.4.3/lib/vagrant-triggers/action/trigger.rb:59:in `block in fire_triggers'
    from /home/pete/.vagrant.d/gems/gems/vagrant-triggers-0.4.3/lib/vagrant-triggers/action/trigger.rb:56:in `each'
    from /home/pete/.vagrant.d/gems/gems/vagrant-triggers-0.4.3/lib/vagrant-triggers/action/trigger.rb:56:in `fire_triggers'
    from /home/pete/.vagrant.d/gems/gems/vagrant-triggers-0.4.3/lib/vagrant-triggers/action/trigger.rb:18:in `call'
    from /usr/lib/ruby/vendor_ruby/vagrant/action/warden.rb:34:in `call'
    from /usr/lib/ruby/vendor_ruby/vagrant/action/builder.rb:116:in `call'
    from /usr/lib/ruby/vendor_ruby/vagrant/action/runner.rb:69:in `block in run'
    from /usr/lib/ruby/vendor_ruby/vagrant/util/busy.rb:19:in `busy'
    from /usr/lib/ruby/vendor_ruby/vagrant/action/runner.rb:69:in `run'
    from /usr/lib/ruby/vendor_ruby/vagrant/machine.rb:147:in `action'
    from /usr/share/vagrant/plugins/commands/destroy/command.rb:28:in `block in execute'
    from /usr/lib/ruby/vendor_ruby/vagrant/plugin/v2/command.rb:193:in `block in with_target_vms'
    from /usr/lib/ruby/vendor_ruby/vagrant/plugin/v2/command.rb:191:in `each'
    from /usr/lib/ruby/vendor_ruby/vagrant/plugin/v2/command.rb:191:in `with_target_vms'
    from /usr/share/vagrant/plugins/commands/destroy/command.rb:27:in `execute'
    from /usr/lib/ruby/vendor_ruby/vagrant/cli.rb:38:in `execute'
    from /usr/lib/ruby/vendor_ruby/vagrant/environment.rb:484:in `cli'
    from /usr/bin/vagrant:127:in `<main>'

I've tried a number of different run commands, but I currently have it set to simple 'ls' as I figured it was about as simple as it gets.

config.trigger.before :destroy do
  info "running trigger code"
  run "ls"
end

Sorry if this isn't the correct way to inform you of a bug.
Also sorry if this is simply something I'm doing wrong.

Cheers,
Pete

Trying to mysqldump on vagrant halt

Hi there,

I'm trying to achieve a workflow similar to https://github.com/Varying-Vagrant-Vagrants/VVV/ where (if available) the database is imported from a synched folder on vagrant up and exported on vagrant halt, suspend and destroy.

VVV uses an external command from a specific directory /config/homebin/vagrant_halt which referes to another command db_backup in that same directory.

I'm trying to understand how these commands are recognized in their Vagrantfile, because when I try to run the command vagrant_halt in the halt trigger I get an error:

==> default: Running triggers before halt...
==> default: Executing command "vagrant ssh -c vagrant_halt"...
==> default: bash: vagrant_halt: command not found
==> default: Command execution finished.
The command "vagrant ssh -c 'vagrant_halt'" returned a failed exit code. The
error output is shown below:

bash: vagrant_halt: command not found

Which makes sense. So my first question is how can I run a command in the vagrant-triggers that's in a separate command file?

As a workaround I tried to run the db_backup lines directly in the vagrant-trigger like this:

if Vagrant.has_plugin? 'vagrant-triggers'
  config.trigger.before :halt, :stdout => true do
    wordpress_sites.each do |(name, site)|
      db_name  = site['env']['db_name']
      db_user  = site['env']['db_user']
      db_pass  = site['env']['db_password']
      info "Backing up #{db_name}"
      run "vagrant ssh -c mysqldump -u#{db_user} -p#{db_pass} #{db_name} > /srv/database/backups/#{db_name}.sql && echo 'Database #{db_name} backed up';"
    end
  end
else
  puts 'vagrant-triggers missing, please install the plugin:'
  puts 'vagrant plugin install vagrant-triggers'
end

Where db_name, db_user & db_pass are specified in a group_vars/development file.
The loop and variables all work, but I keep on getting the following error when running vagrant halt:

==> default: Running triggers before halt...
==> default: Backing up example_dev
==> default: Executing command "vagrant ssh -c mysqldump -uusername -ppassword example_dev > /srv/database/backups/example_dev.sql && echo Database example_dev backed up;"...
==> default: An invalid option was specified. The help for this command
==> default: is available below.
==> default: 
==> default: Usage: vagrant ssh [options] [name] [-- extra ssh args]
==> default: 
==> default: Options:
==> default: 
==> default:     -c, --command COMMAND            Execute an SSH command directly
==> default:     -p, --plain                      Plain mode, leaves authentication up to user
==> default:     -h, --help                       Print this help
==> default: Command execution finished.
The command "vagrant ssh -c mysqldump -uusername -ppassword example_dev > /srv/database/backups/example_dev.sql && echo 'Database example_dev backed up';" returned a failed exit code. The
error output is shown below:

An invalid option was specified. The help for this command
is available below.

Usage: vagrant ssh [options] [name] [-- extra ssh args]

Options:

    -c, --command COMMAND            Execute an SSH command directly
    -p, --plain                      Plain mode, leaves authentication up to user
    -h, --help                       Print this help

What exactly is this invalid option that is specified?
I tried running it without the -c flag but that makes no difference.

Thanks for your help!

Execute a trigger before/after/instead_of *any* command

Hello,

I have a specific use case, where I need to copy a private key to a temporary location and assign it proper access rights. I need this copy because it's impossible to correctly control the file access rights from a directory on windows host mapped to the Ubuntu guest.

....
override.ssh.username = "ubuntu"
override.ssh.private_key_path = "/local_ubuntu_directory/default.pem"
....

To do this I used your plugin:

  config.trigger.before [:up, :provision ....]  do
     run "sudo /bin/cp /mapped_directory/default.pem /local_ubuntu_directory/"
     run "sudo /bin/chmod 0600 /local_ubuntu_directory/default.pem"
     run "sudo /bin/chown vagrant:vagrant /local_ubuntu_directory/default.pem"
   end

  config.trigger.after [:up, :provision ....] do
    run "sudo /bin/rm -f /local_ubuntu_directory/default.pem"
  end

But I have two problem with this:

  1. Security issue, if a vagrant command fails I don't get the temporary key deleted
  2. I have to list every possible vagrant command in the trigger, because if I don't include a command, it will fail with "file not found" error (vagrant enforces override.ssh.private_key_path file existence): is there an easy way to specify 'any' command?

Access machine ID from trigger

How do I access the ID of the current virtual machine inside a trigger? The following works, but there must be a better way:

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.provider "virtualbox" do |vb, override|
    # Use VBoxManage to customize the VM. For example to change memory:
    vb.customize ["modifyvm", :id, "--memory", "1536"]

    override.trigger.after :halt, :append_to_path => ENV["VBOX_INSTALL_PATH"] do
      run "VBoxManage storageattach " +
        File.read(".vagrant/machines/default/virtualbox/id") +
        " --storagectl SATA --port 1 --medium none"
    end
  end
end

Also on SO: http://stackoverflow.com/q/26985575/946850.

1.6 prevents running vagrant ssh commands

Using the method you recommended here with this in my Vagrantfile

config.trigger.before :halt do
  run "vagrant ssh -c 'vagrant_halt'"
end
config.trigger.before :suspend do
  run "vagrant ssh -c 'vagrant_suspend'"
end
config.trigger.before :destroy do
  run "vagrant ssh -c 'vagrant_destroy'"
end

I get this error when trying to do vagrant halt:

The command "vagrant ssh -c 'db_backup'" returned a failed exit code. The
error output is shown below:

An action 'ssh_run' was attempted on the machine 'default',
but another process is already executing an action on the machine.
Vagrant locks each machine for access by only one process at a time.
Please wait until the other Vagrant process finishes modifying this
machine, then try again.

If you believe this message is in error, please check the process
listing for any "ruby" or "vagrant" processes and kill them. Then
try again.

Looking at the changelog for version 1.6, there is this:

core: Vagrant locks machine access to one Vagrant process at a time. This will protect against two simultaneous up actions happening on the same environment.

For now, I've downgraded to 1.5.4 and it is working again.

Cannot mount network share after "up"

I have added a trigger like this:

config.trigger.after :up do
  run "net use Z: \\\\192.168.33.10\\webroot"
end

This fails however:

System error 67 has occurred
The network name cannot be found

If I run the command manually from command line after starting the machine, the mount drive is added perfectly fine however.

Any ideas? I already tried sleeping to no avail.

triggers are ignored when provider is 'aws'

If you do this

vagrant up --provider aws

with the Vagrantfile below then the trigger does not fire.

Do

vagrant up

and trigger fires as expected.

I'm guessing the 'up' is intercepted by the vagrant-aws plugin when aws is the default provider.

Any easy way around this?


Vagrant.configure("2") do |config|
  config.vm.box = "docker-server"
  config.trigger.before :up do
  confirm = nil
  until ["Y", "y", "N", "n"].include?(confirm)
    confirm = ask "Would you really like to bring up the VM? (Y/N) "
  end
  exit unless confirm.upcase == "Y"
  end

  config.vm.provider :aws do |aws, override|
  end
end

Net::HTTPNotFound: No gems found matching "vagrant-vmware-workstation" "3.1.0" nil

OSX10.9.5
Vagrant 1.6.5
Vbox 4.3.20

I'm still unsure if this is a Vagrant or ruby issue, but when I try to install through

vagrant plugin install vagrant-triggers

I get

Installing the 'vagrant-triggers' plugin. This can take a few minutes...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:

Net::HTTPNotFound: No gems found matching "vagrant-vmware-workstation" "3.1.0" nil

But I've managed to install using

gem install --install-dir ~/.vagrant.d/gems vagrant-triggers -v '0.4.2'

vagrant-triggers ingore `after` condition

vagrant version : 1.3.5
os : centos 6.4 x86_64

I find out that vagrant-triggers ingore after condition, only execute before condition,

and I resolve this by change the code in lib/config.rb
change this line =>
@triggers << { :action => action, :condition => :before, :options => options }
with this line =>
@triggers << { :action => action, :condition => condition, :options => options }

and it's work!!!

Display / capture coloured output in post-provision run

Firstly, great plugin, thanks very much for putting this together!

I'm currently using this to implement ServerSpec tests directly following a successful puppet provisioning run ... and it would be awesome if the plugin were able to maintain/preserve the coloured output of the ServerSpec run, to make the output easier to read at first glance. We use the standard shell provisioner to execute the puppet run, and this preserves the coloured output of puppet's resource management.

The Vagrant documentation suggests setting keep_color bool to true to preserve the native script output colour, and this appears to be the default .. is there perhaps a way to default this to true for the vagrant-trigger run as well?

Is this a feature that you would potentially support at some point? If the behaviour I'm experiencing is not expected, are there any configuration options I can set to ensure coloured output is preserved?

Thanks in advance :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.