ansible-role-yedit icon indicating copy to clipboard operation
ansible-role-yedit copied to clipboard

Better support of comments

Open dr4Ke opened this issue 5 years ago • 5 comments

Take this file.yml:

variables:
  var1: VAR1

#This is another definition
other:
  var2: VAR2

Use this task:

- name: add variable
  yedit:
    src: file.yml
    key: variables.var3
    value: VAR3

You end up with file.yml:

variables:
  var1: VAR1

#This is another definition
  var3: VAR3
other:
  var2: VAR2

It's correct in a functional point of view but ugly. It would be better to have:

variables:
  var1: VAR1
  var3: VAR3

#This is another definition
other:
  var2: VAR2

dr4Ke avatar Sep 25 '19 13:09 dr4Ke

I suspect this is related to the ruamel.yaml module, not in this one.

dr4Ke avatar Sep 25 '19 13:09 dr4Ke

Upstream report: https://bitbucket.org/ruamel/yaml/issues/323/enhancement-insert-new-dict-keys-right

dr4Ke avatar Sep 26 '19 06:09 dr4Ke

In my case it removes all the comments in the YAML file. @dr4Ke Has it happened to you?

Xtigyro avatar Apr 17 '21 21:04 Xtigyro

I don't remember such a thing, but I have not used it in a while, so…

dr4Ke avatar Apr 22 '21 18:04 dr4Ke

@Xtigyro same to me. it removed all comments and empty lines.

amg-web avatar Jul 07 '22 09:07 amg-web