# Ansible-config line wrapping

**URL:** <https://forum.ansible.com/t/ansible-config-line-wrapping/4690>\
**Category:** Get Help\
**Tags:** config, python\
**Created:** [April 2, 2024, 10:27pm UTC](https://forum.ansible.com/t/ansible-config-line-wrapping/4690 "2024-04-02T22:27:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [April 2, 2024, 10:27pm UTC](https://forum.ansible.com/t/ansible-config-line-wrapping/4690/1 "2024-04-02T22:27:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [April 2, 2024, 10:44pm UTC](https://forum.ansible.com/t/ansible-config-line-wrapping/4690/2 "2024-04-02T22:44:35Z")

</div>

You can work around the issue by getting the config as JSON and then converting it into YAML, for example using [yq](https://github.com/mikefarah/yq):

```bash
ansible-config list --format json | yq -o=yaml -P

```

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [April 3, 2024, 12:00am UTC](https://forum.ansible.com/t/ansible-config-line-wrapping/4690/3 "2024-04-03T00:00:59Z")

</div>

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.

```auto
$ 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

```

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [April 3, 2024, 3:44pm UTC](https://forum.ansible.com/t/ansible-config-line-wrapping/4690/4 "2024-04-03T15:44:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 3, 2024, 3:44pm UTC](https://forum.ansible.com/t/ansible-config-line-wrapping/4690/5 "2024-05-03T15:44:54Z")

</div>

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