I have a web application that uses a YAML file for configuration. This is an except from the file:

```
---
settings:
  domain: 127.0.0.1

```

I have an Ansible playbook that uses the lineinfile module to replace the IP address in the YAML file above with the server's public IP address. 

```
- name: Discovering Public Internet Protocol Address
  ipify_facts:
  register: public_ip

- name: Configuring Application with discovered Public IP
  lineinfile:
    dest: /application/path/settings.yml
    regexp: '^(.*)domain: (.*)$'
    line: 'domain: {{ ipify_public_ip }}'

```

This finds and replaces the 127.0.0.1 IP with the public server's IP but it breaks the YAML indentation as follows:

```
---
settings:
domain: 54.12.33.3

```

Problem: "domain" is moved to the same line with "settings" and my ruby app fails to run migrations because it identifies a YAML syntax error.

I do not mind replacing lineinfile with another module, but I'd like to keep it if possible. I've been struggling with this for hours and will appreciate any assistance.