Search code examples
rubyyamltest-kitchen

Kitchen .kitchen.yml multiple-line environment variable


With Kitchen I am trying to define an attribute with a multiple-line environment variable using .kitchen.yml such as :

attributes:
  foo:
    ssh:
      key_private: <%= ENV['CHEF_SSH_KEY_PRIVATE'] %>

The multi-line CHEF_SSH_KEY_PRIVATE variable looks like:

-----BEGIN RSA PRIVATE KEY-----
...
...
-----END RSA PRIVATE KEY-----

This method works perfectly fine with single-line variables, however the file cannot be parsed when using multi-line variable. I suspect the "compiled" file does not have proper indentation, but I cannot set indentation directly on the variable as it may be used in other YAML files requiring a different indentation level.

How can I properly use multi-line environment variable in YAML without parsing issues?


Solution

  • You can set the environment variable to contain a double-quoted single-line string with escaped newlines, like

    "-----BEGIN RSA PRIVATE KEY-----\n...\n...\n-----END RSA PRIVATE KEY-----"
    

    This is safe to include at any position of a YAML document where a content node is expected.