strip_dict_keys – Remove top-level keys from a YAML file
Synopsis
Reads a YAML file, removes every top-level key that appears in any of the provided key-source YAML files, and writes the result back.
Parameters
- src (True, str, None)
Path to the YAML file whose keys will be stripped.
- keys_from (True, list, None)
List of paths to YAML files whose top-level keys identify which keys to remove from src.
- dest (False, str, None)
Path to write the result. If omitted, src is overwritten in place.
Examples
- name: Strip keys from exclusion files out of reproducer-variables
cifmw.general.strip_dict_keys:
src: /tmp/reproducer-variables.yml
keys_from:
- /home/zuul/configs/excluded_vars.yaml
- /home/zuul/configs/other_excluded.yaml
- name: Strip keys and write to a different file
cifmw.general.strip_dict_keys:
src: /tmp/reproducer-variables.yml
keys_from:
- /home/zuul/configs/excluded_vars.yaml
dest: /tmp/stripped-variables.yml
Return Values
- removed_keys (always, list, [‘cifmw_discovered_image_url’, ‘cifmw_other_var’])
The list of top-level keys that were removed.
- src (always, str, )
The source file path.
- dest (always, str, )
The destination file path.