'In YAML how can I comment a part of a line?

In YAML how can I comment a part of a line?

for example:

- name: "JAVA_OPTIONS"
value: "-Dconfig.dir.path=$(CONF_PATH) -Dpoint.dir.path=$(POINT_PATH)-
Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$(LOG_PATH) 
-DMY_POD_NAME=$(MY_POD_NAME)"

How can I comment a string inside the value line?

Like "-Dpoint.dir.path=$(POINT_PATH)" will be remarked but all the rest will take affect.



Solution 1:[1]

YAML only has comments that are in effect until the end of the line. So unless there is some other commenting mechanism implemented by the program that interprets the YAML data (unlikely), the best thing to do is copy the whole line, comment one version out, and adjust the other:

- name: "JAVA_OPTIONS"
  # value: "-Dconfig.dir.path=$(CONF_PATH) -Dpoint.dir.path=$(POINT_PATH)-Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$(LOG_PATH) -DMY_POD_NAME=$(MY_POD_NAME)"
  value: "-Dpoint.dir.path=$(POINT_PATH)-Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$(LOG_PATH) -DMY_POD_NAME=$(MY_POD_NAME)"

If you want to "roll-back" just move the comment token (#) from the one line to the other.

In the above I adjusted your input to be valid YAML. Your example is not valid because you cannot have both a sequence element and a key-value pair on the same level with the same parent (in this case the YAML document root).

Solution 2:[2]

In your specific example, you could break individual arguments out to separate lines in a folded scalar. As long as argument order isn't an issue, anything to comment can just be moved to the end. It will work fine as long as you don't stick it in the middle.

- name: "JAVA_OPTIONS"
  value: >
    -XX:+HeapDumpOnOutOfMemoryError 
    -Xms256m
    -Xmx512m 
    -XX:HeapDumpPath="$(LOG_PATH)"
    -DMY_POD_NAME="$(MY_POD_NAME)"
#    -Dconfig.dir.path="$(CONF_PATH)"
#    -Dpoint.dir.path="$(POINT_PATH)"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anthon
Solution 2 Paul Hodges