Ansible-config line wrapping

When I run “ansible-config list”, something is taking the nice, long lines of text from ansible/config/base.yml and wrapping it at about 90 columns. I’ve been searching through python source files for longer than I care to admit trying to find what’s doing it.

I want to play with giving the user some control over the width of those output lines, perhaps with an explicit parameter or implicitly through the CLI window’s width ($COLUMNS). That would be a lot easier to do if I could find where the line breaks are happening.

If anybody can drop me a hint, I’d appreciate it very much.

You can work around the issue by getting the config as JSON and then converting it into YAML, for example using yq:

ansible-config list --format json | yq -o=yaml -P
2 Likes

If you’re using yq anyway you might as well skip the step of outputting it as JSON, since YAML is just as parseable.

And the answer to “What’s doing the wrapping?” is PyYAML; that’s what it considers a reasonable default representation for scalars.

$ python3
Python 3.9.18 (main, Jan  4 2024, 00:00:00)
[GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>> print(yaml.safe_dump({'foo': 'c c' * 30}))
foo: c cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
  cc cc cc cc c
2 Likes

The normal ‘pager’ we use for most output from CLI that is not a play, does wrapping automatically by checking the TTY size. It should automatically detect that it is outputting to a pipe and avoid wrapping then, we also have a couple of PRs to avoid wrapping as an option.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.