Reputation: 2184
I would like to assign the exit code of an inline shell script in a Vagrantfile to a variable:
FOO = config.vm.provision "shell",
env: {
"FILE" => "/tmp/hello"
},
inline: <<-SHELL
[ -f "$FILE" ]; echo $?
SHELL
and then use it later in my Vagrantfile, like:
if FOO != 0
...
The way I tried it obviously doesn't work. Does anyone here know
Upvotes: 1
Views: 1472
Reputation: 2448
After landing here I realized you can actually assign the output of a command exit code as in ruby:
FOO = `mycommand`
BAR = $?.exitstatus
Then use it in Vagrantfile
as any other variable.
Upvotes: 0
Reputation: 2184
I ended up using an approach like this one.
Something I discovered along the way is that all Ruby conditionals in the Vagrantfile are evaluated in the very beginning, although the inline Shell scripts inside these conditionals (if there are any) are not evaluated at the same time. This lead to some strange behavior, which I could avoid by doing like I said above.
Upvotes: 0