pypyr.steps.filewriteyaml permalink

create yaml file from any context object permalink

Format & write a payload to a yaml file on disk. This is useful for generating yaml files from your pipeline such as when you want to create configuration files dynamically on the fly.

filewriteyaml works like this:

- name: pypyr.steps.filewriteyaml
  comment: write context payload out to yaml
    path: /path/to/output.yaml # destination file
    payload: # (optional) payload to write to path
      key1: value1 # output yaml will have
      key2: value2 # key1 and key2 as string.
      key3: 124 # output int
      key4: false # output bool

This will generate the following json to /path/to/output.yaml:

key1: value1
key2: value2
key3: 123
key4: false

Note that the correct data types will serialize to the generated output yaml. More complicated hierarchical nested structures will also just work.

If you do not specify payload, pypyr will write the entire context to the output file in yaml format. Be careful if you have sensitive values like passwords or private keys!

format yaml with token replacements permalink

All inputs support substitutions. This means you can specify another context item to be the path and/or the payload, for example:

arbkey: arbvalue
writehere: /path/to/output.yaml
  this: yaml content
  will: be written to
  thepath: with substitutions like this {arbkey}.
  path: '{writehere}'
  payload: '{writeme}'

Substitution processing runs on the output. In this example, in the output yaml file created at /path/to/output.yaml, the {arbkey} expression in the last line will substitute like this:

this: yaml content
will: be written to
thepath: with substitutions like this arbvalue.

See a worked filewriteyaml example.

see also

last updated on .