# Wrapping and commenting a block of text for a config file

**URL:** <https://forum.ansible.com/t/wrapping-and-commenting-a-block-of-text-for-a-config-file/41035>\
**Category:** Get Help\
**Created:** [March 13, 2025, 5:29pm UTC](https://forum.ansible.com/t/wrapping-and-commenting-a-block-of-text-for-a-config-file/41035 "2025-03-13T17:29:12Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [March 13, 2025, 5:29pm UTC](https://forum.ansible.com/t/wrapping-and-commenting-a-block-of-text-for-a-config-file/41035/1 "2025-03-13T17:29:12Z")

</div>

I’m working on [a valkey role](https://git.coop/webarch/valkey) and using a [template](https://git.coop/webarch/valkey/-/blob/main/templates/valkey.conf.j2) to generate the configuration file(s) and using the `description` from the [argument specification](https://git.coop/webarch/valkey/-/blob/main/meta/argument_specs.yml) to generate a comment for each variable using this:

```yaml
{{ valkey_argument_spec_options[valkey_var_pair.key].description
   | wordwrap(78)
   | ansible.builtin.comment(beginning="",decoration="# ",end="",newline="",postfix="",prefix="",)
}}

```

Which generates a mess:

```auto
##O#n#e# #o#r# #m#o#r#e# #I#P# #a#d#d#r#e#s#s#e#s# #t#h#a#t# #t#h#e# #i#n#s#t#a#n#c#e# #s#h#o#u#l#d# #b#i#n#d# #t#o#,# #e#a#c#h# #a#d#d
#r#e#s#s# #c#a#n# #b#e#
#p#r#e#f#i#x#e#d# #b#y# #"#-#"#,# #w#h#i#c#h# #m#e#a#n#s# #t#h#a#t# #t#h#e# #s#e#r#v#e#r# #w#i#l#l# #n#o#t# #f#a#i#l# #t#o# #s#t#a#r#t#
 #i#f# #t#h#e#
#a#d#d#r#e#s#s# #i#s# #n#o#t# #a#v#a#i#l#a#b#l#e#.#
bind 127.0.0.1 -::1

```

When I want something like this:

```auto
# One or more IP addresses that the instance should bind to,
# each address can be prefixed by "-", which means that the
# server will not fail to start if the address is not available.
bind 127.0.0.1 -::1

```

Sorry I’m finding the lack of examples on the [comment filter documentaion page](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/comment_filter.html) hard to cope with and can’t work out what options I need… 🙄

---

<div class="post-metadata">

**Author:** ![kristianheljas](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kristianheljas/32/7702_2.png) [@kristianheljas](https://forum.ansible.com/u/kristianheljas)\
**Post date:** [March 13, 2025, 5:37pm UTC](https://forum.ansible.com/t/wrapping-and-commenting-a-block-of-text-for-a-config-file/41035/2 "2025-03-13T17:37:17Z")

</div>

You are setting `newline=''` which causes the every character to be separetely commented.

I suppose you wanted to suppress empty lines in the front and back.

Try this:

```auto
comment(prefix_count=0, postfix_count=0)

```

---

<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:** [March 13, 2025, 5:39pm UTC](https://forum.ansible.com/t/wrapping-and-commenting-a-block-of-text-for-a-config-file/41035/3 "2025-03-13T17:39:39Z")

</div>

That’s done the job 🙂

```auto
# One or more IP addresses that the instance should bind to, each address can be
# prefixed by "-", which means that the server will not fail to start if the
# address is not available.
bind 127.0.0.1 -::1

```

Thanks!

---

<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:** [April 12, 2025, 5:39pm UTC](https://forum.ansible.com/t/wrapping-and-commenting-a-block-of-text-for-a-config-file/41035/4 "2025-04-12T17:39:44Z")

</div>

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