ansible.builtin.comment filter – comment out a string

Note

This filter plugin is part of ansible-core and included in all Ansible installations. In most cases, you can use the short plugin name comment. However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.comment for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same filter plugin name.

Synopsis

  • Use programming language conventions to turn the input string into an embeddable comment.

Input

This describes the input of the filter, the value before | ansible.builtin.comment.

Parameter

Comments

Input

string / required

String to comment.

Positional parameters

This describes positional parameters of the filter. These are the values positional1, positional2 and so on in the following example: input | ansible.builtin.comment(positional1, positional2, ...)

Parameter

Comments

style

string

Comment style to use.

Choices:

  • "plain" ← (default)

  • "decoration"

  • "erlang"

  • "c"

  • "cblock"

  • "xml"

Keyword parameters

This describes keyword parameters of the filter. These are the values key1=value1, key2=value2 and so on in the following example: input | ansible.builtin.comment(key1=value1, key2=value2, ...)

Parameter

Comments

beginning

string

Indicator of the start of a comment block, only available for styles that support multiline comments.

decoration

string

Indicator for comment or intermediate comment depending on the style.

end

string

Indicator the end of a comment block, only available for styles that support multiline comments.

newline

string

Indicator of comment end of line, only available for styles that support multiline comments.

Default: "\\n"

postfix

string

Indicator of the end of each line inside a comment block, only available for styles that support multiline comments.

postfix_count

integer

Number of times to add a postfix at the end of a line, when a prefix exists and is usable.

Default: 1

prefix

string

Token to start each line inside a comment block, only available for styles that support multiline comments.

prefix_count

integer

Number of times to add a prefix at the start of a line, when a prefix exists and is usable.

Default: 1

Notes

Note

  • When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters: input | ansible.builtin.comment(positional1, positional2, key1=value1, key2=value2)

Examples

# commented =>  #
#               # Plain style (default)
#               #
commented: "{{ 'Plain style (default)' | comment }}"

# not going to show that here ...
verycustom: "{{ "Custom style" | comment('plain', prefix='#######\n#', postfix='#\n#######\n   ###\n    #') }}"

Return Value

Key

Description

Return value

string

The ‘commented out’ string.

Returned: success

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.