- 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)", "") }}'
On Monday, April 24, 2023 at 9:37:19 AM UTC-7 Joefrey wrote:
> 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.
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/f520ae4a-b4bd-4f89-a778-6f4c2f0421fbn%40googlegroups.com.