YAML reference another variable in another file

Dmitri picture Dmitri · Mar 25, 2014 · Viewed 13.5k times · Source

Suppose I have 2 YAML files:

1) application.yml

en:
  variable: "Hello World"

2) user.yml

en:
  variable: <Here I want to get value from application.yml -> "Hello World" >

At first I though that I might use referencing:

1) application.yml

en:
  variable: &variable "Hello World"

2) user.yml

en:
  variable: *variable

But turned out that it is only possible for items declared in one file. Is there any way I can get the value from the variable defined in application.yml ?

Answer

Paul Sweatte picture Paul Sweatte · Jul 3, 2014

So the only way is to create another, third file that would hold shared values. Or to use the value from "application.yml".

YAML references are intra-file.

You could also have a preprocessing step where you merge YAML files.

In *nix shell:

cat foo.yaml bar.yaml > baz.yaml

In Powershell:

cat foo.yaml, bar.yaml > baz.yaml

In batch:

type foo.yaml bar.yaml > baz.yaml

References