0

I need to convert a text file which has yaml data into yaml file with proper indentation as mentioned below.

Text file:

---
apiVersion: kubeadm.k8s.io/v1beta2
kind: JoinConfiguration
discovery:
bootstrapToken:
token:
apiServerEndpoint: ":6443"
caCertHashes:
- "sha256:"
nodeRegistration:
name:
kubeletExtraArgs:
cloud-provider: aws

Expected output:

---
apiVersion: kubeadm.k8s.io/v1beta2
kind: JoinConfiguration
discovery:
  bootstrapToken:
    token:
    apiServerEndpoint: ":6443"
    caCertHashes:
      - "sha256:"
nodeRegistration:
  name:
  kubeletExtraArgs:
    cloud-provider: aws
oguz ismail
  • 1
  • 16
  • 47
  • 69
Vageesh S M
  • 21
  • 1
  • 7
  • Does this answer your question? [Proper indentation for Python multiline strings](https://stackoverflow.com/questions/2504411/proper-indentation-for-python-multiline-strings) – Umair Mubeen Jan 08 '21 at 07:26
  • 2
    It is pretty hard job here unless you have the schema for your target object. You can consider the YAML in Kubernetes as the JSON object sending to server. So, you will need to define the schema before mapping your txt to correct YAML. – Ryan Siu Jan 08 '21 at 07:35
  • Your first text file is valid YAML. It'd also be (almost) valid YAML if you indented each line two spaces more when the previous line ended with a `:`. How should your code know that _e.g._ `nodeRegistration:` needs to be back at the top level? – David Maze Jan 08 '21 at 12:22

0 Answers0