I need to use replace to find a regexp that includes \n; however, I keep 
getting an error.  How can I properly do this (don't even know if I am 
using back reference correct either, but if I can get past this error I 
think I can figure that part out)?
Thanks in advance!

---
# DNS Update For Ubuntu 18
- name: Update DNS servers
  replace:
    path: /etc/netplan/50-cloud-init.yaml
    regexp: ".*nameservers.*$\n.*addresses:(.*$)"
    replace: "\1 {{ dns1 }}, {{ dns 2}}"
  notify: "{{ handler_name }}"

Error:
TASK [dns_update : include_tasks] 
********************************************************************************************************************************************************************************************************
fatal: [ansible-ub18]: FAILED! => {"reason": "Syntax Error while loading 
YAML.\n  found unknown escape character\n\nThe error appears to have been 
in '/etc/ansible/role/dns_update/tasks/Ubuntu18.yml': line 7, column 15, 
but may\nbe elsewhere in the file depending on the exact syntax 
problem.\n\nThe offending line appears to be:\n\n    regexp: 
\".*nameservers.*$[\\n].*addresses:(.*$)\"\n    replace: \"\\1 {{ dns1 }}, 
{{ dns 2}}\"\n              ^ here\nWe could be wrong, but this one looks 
like it might be an issue with\nmissing quotes.  Always quote template 
expression brackets when they\nstart a value. For instance:\n\n   
 with_items:\n      - {{ foo }}\n\nShould be written as:\n\n   
 with_items:\n      - \"{{ foo }}\"\n"}



-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/23bf3a96-b90c-49f3-93d6-65ff4ac3e5d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to