Reformatting playbooks, roles, tasks, etc to "canonical" form

Hi all;

Our company has 150+ files in an ansible repository, written by many authors over years.

I’d like to reformat them into a canonical format, so that we can write utilities to update them without having to handle all the variations.

I tried to use the python version of [yq](https://kislyuk.github.io/yq/) to do it:

The YAML spec states that comments should not impact serialization or representation, and are not tied to any particular node. As such, YAML parsers that follow the spec, or try to closely follow the spec, discard comments.

The ansible project utilizes PyYAML which is the official Python YAML parser, and as such, discards comments.

ruamel.yaml however, does have functionality to try and keep comments, but the ansible project does not use this parser.

Effectively, you would have to be bound by a non-spec YAML parser, to enable the functionality you want to use. A community project could implement this, however you will run into issues where something like yamllint, and ruamel.yaml will disagree on formatting, so you’ll need to manually adjust them afterwards.

We did something similar for the system roles project - https://github.com/linux-system-roles/auto-maintenance/#lsr_role2collectionpy - this script was designed to convert legacy roles into collection format, with some rewriting of modules to use the FQCN. It uses ruamel in roundtrip mode so that the yaml that is written is as close to the original as possible. (There are a few problems with ruamel, such as no control of line length wrapping - indentation of embedded comments - and a few other minor nits).