I am having a check.yml file in below format:
apiVersion: v1
kind: ConfigMap
metadata:
name: test
namespace: checking
data:
test.yaml: |
rules:
- name: require-dept
key: dept
value:
regex: ".*"
- name: require-team
key: team
value:
regex: ".*"
Output Expected:
apiVersion: v1
kind: ConfigMap
metadata:
name: test
namespace: checking
data:
test.yaml: |
rules:
- name: require-dept
key: dept
value:
regex: ".*"
- name: require-team
key: team
value:
regex: "test1|test2|test3"
I was looking for a python code to read this yml file and append values to the regex field in key: team, but I couldn't find anything. Please help
I have tried reading the file and saving it but it was changing the format. Code Tried:
import yaml
def set_state():
with open('path + check.yml') as f:
doc = yaml.safe_load(f)
print(doc)
with open('path + check.yml', 'w') as f:
yaml.dump(doc, f)
set_state()