Running Ruby in Triggers / Provisioners

6 views
Skip to first unread message

Jamie Jackson

unread,
Aug 16, 2019, 4:56:47 PM8/16/19
to vagra...@googlegroups.com
With the old `vagrant-triggers` plugin (before Vagrant created its own native triggers), I'd been doing things like this:

  config.trigger.after :destroy do |trigger|

    puts "Removing provisioned directory contents: #{host_provisioned_dir}/*"

    FileUtils.rm_rf Dir.glob("#{host_provisioned_dir}/*")

    puts "Removing WEB-INF from working copy."

    FileUtils.rm_rf("#{host_wwwroot}/WEB-INF")

  end


Is there a way to do run commands using (Vagrant's) ruby within triggers anymore?


I'm also curious as to whether running straight (Vagrant) ruby within provisioners is possible. Like "local" provisioners.


Thanks,

Jamie

Brian Cain

unread,
Aug 16, 2019, 5:52:14 PM8/16/19
to vagra...@googlegroups.com
Hey there!

On Fri, Aug 16, 2019 at 1:56 PM Jamie Jackson <jamie...@gmail.com> wrote:
With the old `vagrant-triggers` plugin (before Vagrant created its own native triggers), I'd been doing things like this:

  config.trigger.after :destroy do |trigger|

    puts "Removing provisioned directory contents: #{host_provisioned_dir}/*"

    FileUtils.rm_rf Dir.glob("#{host_provisioned_dir}/*")

    puts "Removing WEB-INF from working copy."

    FileUtils.rm_rf("#{host_wwwroot}/WEB-INF")

  end


Is there a way to do run commands using (Vagrant's) ruby within triggers anymore?


It is possible, but a little different from the community plugin. You would use the ruby option as documented here: https://www.vagrantup.com/docs/triggers/configuration.html#ruby


  config.trigger.after :destroy do |trigger|
    trigger.ruby do |env, machine|

        puts "Removing provisioned directory contents: #{host_provisioned_dir}/*"
        FileUtils.rm_rf Dir.glob("#{host_provisioned_dir}/*")
        puts "Removing WEB-INF from working copy."
        FileUtils.rm_rf("#{host_wwwroot}/WEB-INF")
    end
  end
 



I'm also curious as to whether running straight (Vagrant) ruby within provisioners is possible. Like "local" provisioners.


This is not currently possible, if I am understanding the question correctly!
 


Thanks,

Jamie

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CA%2BonWPfih-2afX%3Dn0rzAyrmsY_GL8goY%3DFXNhNwt7hcGS950VQ%40mail.gmail.com.


--
Brian Cain

Jamie Jackson

unread,
Aug 19, 2019, 4:51:33 PM8/19/19
to vagra...@googlegroups.com
I missed the ruby option in the docs, thanks!

Reply all
Reply to author
Forward
0 new messages