Search code examples
rubyheredocvagrant-provision

bash heredoc inside a vagrant vm provision heredoc


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.


Solution

  • 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'
    |