0

Below is my sample test.yaml file , in that i received the values for the a and b block and i am trying to completely remove the c block from the file where we have the unhashable keys are present using Python.

applications:
  a:
    chart:
      url-details: https://adbc/a-12.tgz
    images:
      repo: a:23434
  b:
    chart:
      url-details: https://adbc/b-13.tgz
    images:
      repo: b:2345

  c:
    chart:
      url-details: https://adbc/{{ c }}.tgz
    images:
      repo: :{{ c }}

Can someone please help me in giving me some lead on this requirement ?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • 1
    Why don't you open `test.yaml` in a text editor and delete the last 5 lines? – mkrieger1 May 13 '23 at 20:00
  • i would like to automate this operation using python – kishore Kumar May 13 '23 at 20:02
  • 1
    Use [PyYaml](https://pypi.org/project/PyYAML/) to work with `.yaml` files. – SimonUnderwood May 13 '23 at 20:02
  • Does this answer your question? [How to remove last N lines from txt file with Python?](https://stackoverflow.com/questions/54399735/how-to-remove-last-n-lines-from-txt-file-with-python) – mkrieger1 May 13 '23 at 20:02
  • I am trying to completely delete the block in the YAML file where the values are not updated and still with the unhashable key – kishore Kumar May 13 '23 at 20:04
  • in real scenario i dont know how many lines i need to delete , currently in the sample YAML i mentioned **c** block has unhasable keys but in next run **a** block may have unhashable keys , hence i need to delete the blocks dynamically based on the unhashable keys. – kishore Kumar May 13 '23 at 20:07

0 Answers0