The only way that I find to respect regex line break \n is concatenating everything in one line with double quote.
---
- name: Custom prompt output
lineinfile:
path: ~/.zshrc
line: "\n# Custom Prompt\nlocal user=\"%{$fg[yellow]%}%n%{$fg[white]%}@%{$fg[green]%}%m%{$reset_color%}\"\nPROMPT=\"${user} ${PROMPT}\""
state: present
The result is correctly as I expected, but is so ugly. Have a way to better this?