Ansible win_lineinfile Assistance

Good day all,

Not sure If I’m doing something wrong here or hitting a bug.

Goal is to update the below line.

<key=“Token” value=“some_token” />

community.windows.win_lineinfile:
path: ‘{{ some_path }}’
regex: '(.+“Token”.+“).+(” />)
line: ‘$1{{ some_new_token }}$2’
backrefs: true

I end up with:

$1new_token" />

I cannot get $1 to expand when placed directly next to “{{” in line.

line: ‘$1 {{ some_new_token }}$2’ # notice space after $1

Results in:

<key=“Token” value=" new_token" />

Changing my regex and line as below is a workaround, but I’d like to know what I’m missing above.

regex: ‘(.+“Token” value=).+’
line: ‘$1"{{ some_new_token}}" />’

Thank you for any insight.

  • name: Update XML line with new token
    community.windows.win_lineinfile:
    path: ‘{{ some_path }}’
    regex: ‘(<key=“Token” value=“).+(” />)’
    line: ‘{{ line | regex_replace(“(<key=\“Token\” value=).+( \” />)", “\1{{ some_new_token }}\2”) }}’
    vars:
    line: ‘{{ lookup(“file”, some_path) | regex_replace(“(\r|\n)”, “”) }}’