Regex is stripping spaces

The regex is not stripping spaces. You stripped them.

You wrote that the replacement line should not have any leading spaces:

            line: "URL: 'https://{{ result.stdout }}/key/auth'"

If you want leading spaces, you need to put them in. It might look like this:

            line: "    URL: 'https://{{ result.stdout }}/key/auth'"