2

I like to use a bash heredoc inside the ruby heredoc from config.vm.provision, like so:

config.vm.provision "shell", inline: <<-SHELL
    cat >> foobar <<EOF
    bla bla
    foo foo
EOF
echo 'some other command'
SHELL

But when the privision file is executed, everything to the end of the provision ends up in foobar. I suspect that I need some escaping here.

sawa
  • 165,429
  • 45
  • 277
  • 381
reox
  • 5,036
  • 11
  • 53
  • 98

2 Answers2

1

Why do you insist on the nested heredocs? What’s wrong with:

config.vm.provision "shell", inline: %q|
    cat >> foobar <<EOF
    bla bla
    foo foo
EOF
echo 'some other command'
|
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
  • So you've swapped a heredoc for value . Isn't the heredoc supplying a similar ephemeral value? Please help me understand how %q|[something]| won't have the same issue when we use a pipe symbol in the bash script. – user2066657 Oct 03 '18 at 20:43
0

You have to be careful with the indents. This is the revised version of your code, which works as you intend.

Vagrant.configure("2") do |config|
  {{...}}
  config.vm.provision "shell", inline: <<-'SHELL'
    cat >> foobar <<EOF
bla bla
foo foo
EOF
    echo 'some other command'
  SHELL
end
trolzen
  • 119
  • 7