punsoca
punsoca

Reputation: 587

Parameterize YAML file

I am looking to parameterize the value of a variable - like http_proxy in the example below:

   parameters:
  - string:
      name: http_proxy
      default: 'http://myproxy.company.com'

I have two questions:

(1) how do I "parameterize" the default value ('http://myproxy.company.com')? I suppose it can be done like:

default: %proxy_url%

(2) if the above is correct, do I just set it up in a "properties" (or equivalent) file? If so, how do I configure it to make my yaml file read in the proxy_url from the "properties" file? thank you.

Upvotes: 1

Views: 9887

Answers (1)

Mijago
Mijago

Reputation: 1639

In plain YAML, this is not possible.

You have the following options:

  • Edit your YAML-parser to recognize the %proxy_url% and fill it
  • Read the file, replace the %proxy_url% with your desired url and then give the result to the parser
  • Use YAMLs node anchors

The first two solutions do work, and if you can't (or won't) save the proxy_url inside the YAML file, you can not get around these.

But if you can save it in the YAML file, use node anchors - because they are awesome!

I give you a very basic example:

defaults:
  proxy_url: &anchor_proxy_url http://myproxy.company.com
server:
  [... i don`t know how your file looks so just an example here]
  parameters:
   - string:
     name: http_proxy
     default: *anchor_proxy_url

Side note: If you want to use the - string: to indicate that the following entry is of kind string, i'll recommend you to use YAML tags - because they are also awesome.

Upvotes: 2

Related Questions