1

I'm preparing for Ansible certification, and I decided that ansible-doc -s may be useful to speed up creation of playbooks. It dumps a snippet of configuration of the requested module, with all options and comments describing them, like so:

$ansible-doc -s file

- name: Manage files and file properties
  file:
      access_time:           # This parameter indicates the time the file's access time should be set to. Should be `preserve' when no modification is required,
                               `YYYYMMDDHHMM.SS' when using default time format, or `now'. Default is `None' meaning that `preserve' is
                               the default for `state=[file,directory,link,hard]' and `now' is default for `state=touch'.
      access_time_format:    # When used with `access_time', indicates the time format that must be used. Based on default Python format (see time.strftime doc).
      attributes:            # The attributes the resulting file or directory should have. To get supported flags look at the man page for `chattr' on the target
                               system. This string should contain the attributes in the same order as the one displayed by `lsattr'. The
(...)

I then learn that I can easily insert that into a file on vim, using something like :r! ansible-doc -s file. Except that, when I do that, the file gets weirdly formatted:

- name: Manage files and file properties
  file:
      access_time:           # This parameter indicates the time the file's
                               access time
                               should be set to.
                               Should be
                               `preserve' when
                               no modification
                               is required,
(...)

If I was to fix that formatting, I'd lose time instead of saving it.

I have noticed that it is not a vim thing; if I pipe the output of ansible-doc or redirect it to a file, the same happens. I tried setting PAGER=cat, to not avail; it respects that environment variable and replaces less with cat, but still changes the formatting.

Apparently, whenever ansible-doc sees a non-tty stdout, it uglifies the output. Anybody knows how to fix that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.