I am working on an object where first python reads YAML, does some changes and then writes them back to file. Loading and updating values part is working fine but when I go to write the file it makes lists rather separate docs.
testing.yaml
apiVersion: v1
data:
databag1: try this
databag2: then try this
kind: ConfigMap
metadata:
name: data bag info
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: data-bag-service
name: data-bag-tagging
Code block
import yaml
with open("./testing.yaml", "r") as stream:
deployment_dict= list(yaml.safe_load_all(stream))
print(deployment_dict)
with open("./testing.yaml", "w") as service_config:
yaml.dump(
deployment_dict,
service_config,
default_flow_style=False
)
Transformation I am getting: testing.yaml
- apiVersion: v1
data:
databag1: try this
databag2: then try this
kind: ConfigMap
metadata:
name: data bag info
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: data-bag-service
name: data-bag-tagging
How can I achieve the original state with the ---
end-of-directive indicators?