In a YAML folded scalar a backslash is just a backslash

A regex written as '\\s' inside a >- block never matched, so every node in my upgrade role looked outdated. Backslashes are literal in folded and literal scalars; double them only in double-quoted strings.

My upgrade role compares each node’s schematic with the wanted one and upgrades only the nodes that differ. Every node looked outdated, whatever it was running.

The check lived in a folded scalar:

up_to_date: >-
  {{ output is search('\\sschematic\\s' ~ wanted) }}

I had written the regex the way you would in a double-quoted string, with every backslash doubled. In >- (and |) block scalars nothing is an escape sequence, so Jinja received two literal backslashes followed by s: a regex for a backslash, then the letter. It never matched, so every node counted as outdated.

Rule

up_to_date: >-
  {{ output is search('\sschematic\s' ~ wanted) }}            # single backslash

pattern: "\\sschematic\\s"                                       # doubled, only in double quotes

Single backslash in folded and literal blocks and in plain and single-quoted scalars; double it only inside double quotes. When a regex “never matches”, print the string the template actually received before you start debugging the pattern.