From 455aff84364ee6ba34382cee9c2fb8a58dc058e4 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 21 Mar 2017 16:03:00 -0400 Subject: [PATCH] ported fix from ansible-core #5639 From 3d09c94faeaa52075055f23744d8b52581c59bb2 Mon Sep 17 00:00:00 2001 Evan Kaufman --- lib/ansible/modules/files/replace.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/ansible/modules/files/replace.py b/lib/ansible/modules/files/replace.py index 60d5500cfd..ff82ce5f0a 100644 --- a/lib/ansible/modules/files/replace.py +++ b/lib/ansible/modules/files/replace.py @@ -52,6 +52,10 @@ options: U(http://docs.python.org/2/library/re.html). Uses multiline mode, which means C(^) and C($) match the beginning and end respectively of I(each line) of the file. + - Note that, as of ansible 2, short form tasks should have any escape + sequences backslash-escaped in order to prevent them being parsed + as string literal escapes. See the examples. + replace: required: false description: @@ -141,6 +145,15 @@ EXAMPLES = r""" regexp: '^(NameVirtualHost|Listen)\s+80\s*$' replace: '\1 127.0.0.1:8080' validate: '/usr/sbin/apache2ctl -f %s -t' + +- name: short form task (in ansible 2+) necessitates backslash-escaped sequences + replace: dest=/etc/hosts regexp='\\b(localhost)(\\d*)\\b' replace='\\1\\2.localdomain\\2 \\1\\2' + +- name: long form task does not + replace: + dest: /etc/hosts + regexp: '\b(localhost)(\d*)\b' + replace: '\1\2.localdomain\2 \1\2' """ import os