From 748304daddde260231c86af1b48e25d049067c93 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Sat, 12 Sep 2020 20:10:31 +0200 Subject: [PATCH] interfaces_file: re.escape() old value (#880) --- changelogs/fragments/777-interfaces_file-re-escape.yml | 3 +++ plugins/modules/system/interfaces_file.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/777-interfaces_file-re-escape.yml diff --git a/changelogs/fragments/777-interfaces_file-re-escape.yml b/changelogs/fragments/777-interfaces_file-re-escape.yml new file mode 100644 index 0000000000..a7daee5670 --- /dev/null +++ b/changelogs/fragments/777-interfaces_file-re-escape.yml @@ -0,0 +1,3 @@ +--- +bugfixes: +- interfaces_file - escape regular expression characters in old value (https://github.com/ansible-collections/community.general/issues/777). diff --git a/plugins/modules/system/interfaces_file.py b/plugins/modules/system/interfaces_file.py index 7684bf485e..6f5c3a618c 100644 --- a/plugins/modules/system/interfaces_file.py +++ b/plugins/modules/system/interfaces_file.py @@ -284,7 +284,7 @@ def setInterfaceOption(module, lines, iface, option, raw_value, state, address_f address_family = target_option['address_family'] prefix_start = old_line.find(option) optionLen = len(option) - old_value_position = re.search(r"\s+".join(old_value.split()), old_line[prefix_start + optionLen:]) + old_value_position = re.search(r"\s+".join(map(re.escape, old_value.split())), old_line[prefix_start + optionLen:]) start = old_value_position.start() + prefix_start + optionLen end = old_value_position.end() + prefix_start + optionLen line = old_line[:start] + value + old_line[end:]