yaml_in_place¶
Hook for modifying a yaml in place (ie read, transform, and write back to the file in one operation). WIP -> https://github.com/sudoblockio/tackle/issues/100.
Inputs¶
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| path | str | True | The file path to put read or write to. | |
| remove | Union[List, str] | None | False | Parameter or regex to remove from list or dict. |
| contents | Union[Dict, List] | None | False | Supplied dictionary or list to write. |
| update | Dict | None | False | Use the python update dict method on contents before writing |
| filter | List | None | False | List or string to values to. |
| merge_dict | dict | None | False | Dict input that recursively overwrites the contents. |
| in_place | bool | False | True | Boolean to read the contents of the path and then write after modifications. |
| append_items | Union[Dict, str, List[Any]] | None | False | List to append to append_key key. |
| append_keys | Union[Dict, str, List[Any]] | None | False | String or list of hierarchical keys to append item to. Defaults |
| mode | str | None | False | The mode that the file should write. Defaults to write 'w'. See https://docs.python.org/3/library/functions.html#open |
| write | bool | None | False |
Arguments¶
| Position | Argument | Type |
|---|---|---|
| 1 | path | str |
| 2 | contents | Union[Dict, List] |
Returns¶
Union[str, dict]
Examples¶
Update keys in a yaml file
update a key in output.yaml:
_>: yaml_in_place output.yaml --in_place
update:
key-to-update:
stuff: things
Filter out items in a list
things:
- stuff
- things
- _stuff
- _thing
- _foo
- bar_
out:
->: yaml_in_place
contents: "{{ things }}"
path: output.yaml
remove:
- ^_
- _$
# output.yaml -> just a list
- stuff
- things