Search code examples
ruby-on-railsdockerboot2docker

Using 'boot2docker ip' in your database.yml?


I'd like to use something like the following in my database.yml:

host: %x(boot2docker ip)

However, whenever I do this, I get back something like the following error:

RuntimeError (YAML syntax error occurred while parsing ...-database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): found character that cannot start any token while scanning for the next token at line 12 column 9):

It seems clear to me that it's something about the way that boot2docker is responding with the ip is wrong, adding a newline or similar. I could put this somewhere else, but it seems right just to do it inline - is there an elegant (one line) way to do this?


Solution

  • Turns out that database.yml is not a ruby file, it is just raw yml, in which templating works. If I want to execute ruby, I need to escape it.

    The answer here was the following:

    host: <%= %x(boot2docker ip) %>