Wrapping and commenting a block of text for a config file

I’m working on a valkey role and using a template to generate the configuration file(s) and using the description from the argument specification to generate a comment for each variable using this:

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

Which generates a mess:

##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:

# 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 hard to cope with and can’t work out what options I need… :roll_eyes:

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:

comment(prefix_count=0, postfix_count=0)
1 Like

That’s done the job :slight_smile:

# 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!

1 Like