0

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()
Nikhil Thomas
  • 53
  • 1
  • 7
  • 2
    „*but it was changing the format*“ See [this question](https://stackoverflow.com/q/60891174/347964). – flyx Jul 02 '21 at 10:14

0 Answers0