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:]