mahmood
mahmood

Reputation: 24795

Using variables in yaml

I have defined an entry in a YAML file like this

run1:
    exec_dir: "/home/mahmood/app/bin/"
    data_dirs: "/home/mahmood/data/1/2/3/"
    execs:
        - sim:
            - args: market input_1.txt

In fact input_1.txt exists in data_dirs. So, I would like to use data_dirs as a variable in the args. How can I define that?

Upvotes: 1

Views: 2752

Answers (1)

flyx
flyx

Reputation: 39768

YAML isn't a programming language, nor is it a templating language. It doesn't have variables (you can use anchors & aliases to simulate variables to some degree though). It doesn't have procedural instructions, and you'd need concatenation/interpolation to insert the scalar content of a YAML node into another YAML node.

Your options are either to use a templating language on top of YAML, which is done by a lot of heavy YAML users like e.g. Ansible and Kubernetes Helm, or you could implement special logic on loading if you are in control of the loading code. If you are writing YAML for an existing tool, chances are that it already provides one of those options.

Upvotes: 3

Related Questions