Thanks, Brian,

My migrations from the vagrant-triggers plugin to the native triggers
implementation have been pretty rough, but thanks for the help so far.

I'm open to (ugly) workarounds since I have to stop spending cycles on
this. Can anybody think of creative workarounds for doing this, whether
it's gaining access to some global scope from the trigger or something else?

Thanks,
Jamie

On Mon, Aug 19, 2019 at 7:02 PM Brian Cain <[email protected]> wrote:

>
>
> On Mon, Aug 19, 2019 at 1:55 PM Jamie Jackson <[email protected]>
> wrote:
>
>> How would I set a variable in a trigger if I wanted it to be available in
>> a provisioner?
>>
>
> Hi there -
>
> Variables defined inside the ruby trigger are limited to that triggers
> scope, and aren't made
> available outside the Ruby block. There are probably some work arounds if
> you need some value
> that the Ruby trigger has if a different provisioner needs it, but a new
> Ruby variables' scope is still
> limited to that Ruby block.
>
> Thanks!
>
>
>>
>> Here's a quick (failing) test case:
>>
>>
>> # -*- mode: ruby -*-
>>
>> # vi: set ft=ruby :
>>
>>
>> Vagrant.configure("2") do |config|
>>
>>   config.vm.box = "ubuntu/bionic64"
>>
>>
>>
>>   config.trigger.before [:up, :provision] do |trigger|
>>
>>     trigger.ruby do |env, machine|
>>
>>       var_derived_in_ruby_trigger = "hi"
>>
>>     end
>>
>>   end
>>
>>
>>
>>   config.vm.provision "read_var_from_trigger",
>>
>>     type: "shell",
>>
>>     privileged: false,
>>
>>     inline: "echo '[#{var_derived_in_ruby_trigger}']"
>>
>>
>>
>> end
>>
>>
>> Output:
>>
>>
>> $ vagrant up
>> Vagrant failed to initialize at a very early stage:
>>
>> There was an error loading a Vagrantfile. The file being loaded
>> and the error message are shown below. This is usually caused by
>> an invalid or undefined variable.
>>
>> Path: /Users/jjackson/eclipse-workspace/simplevagrant/Vagrantfile
>> Line number: 20
>> Message: undefined local variable or method `var_derived_in_ruby_trigger
>>
>>
>> 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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/vagrant-up/CA%2BonWPdK4sZddU_AeiL3F1jWk2%2Bhfgu%2BDY0JawZnnRvj8dzQoA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/vagrant-up/CA%2BonWPdK4sZddU_AeiL3F1jWk2%2Bhfgu%2BDY0JawZnnRvj8dzQoA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Brian Cain
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vagrant-up/CADHESCVnCjJZHtt51k%3D%2BY9JsrkjeUJRUugiPEi7c2Z_pphhpDQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/vagrant-up/CADHESCVnCjJZHtt51k%3D%2BY9JsrkjeUJRUugiPEi7c2Z_pphhpDQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vagrant-up/CA%2BonWPdE8e%2BWf%2BQr0Fc6Tsz%3Ds5H1VjS0GnFSQpF4pSwu0yubxQ%40mail.gmail.com.

Reply via email to