diff --git a/changelogs/fragments/3328-interfaces_file-improvements.yaml b/changelogs/fragments/3328-interfaces_file-improvements.yaml new file mode 100644 index 0000000000..10734af603 --- /dev/null +++ b/changelogs/fragments/3328-interfaces_file-improvements.yaml @@ -0,0 +1,4 @@ +bugfixes: + - interfaces_file - no longer reporting change when none happened (https://github.com/ansible-collections/community.general/pull/3328). +minor_changes: + - interfaces_file - minor refactor (https://github.com/ansible-collections/community.general/pull/3328). diff --git a/plugins/modules/system/interfaces_file.py b/plugins/modules/system/interfaces_file.py index c22c0ce29e..7666ba1cbc 100644 --- a/plugins/modules/system/interfaces_file.py +++ b/plugins/modules/system/interfaces_file.py @@ -148,57 +148,48 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.text.converters import to_bytes -def lineDict(line): +def line_dict(line): return {'line': line, 'line_type': 'unknown'} -def optionDict(line, iface, option, value, address_family): +def make_option_dict(line, iface, option, value, address_family): return {'line': line, 'iface': iface, 'option': option, 'value': value, 'line_type': 'option', 'address_family': address_family} -def getValueFromLine(s): - spaceRe = re.compile(r'\s+') - for m in spaceRe.finditer(s): - pass - valueEnd = m.start() - option = s.split()[0] - optionStart = s.find(option) - optionLen = len(option) - valueStart = re.search(r'\s', s[optionLen + optionStart:]).end() + optionLen + optionStart - return s[valueStart:valueEnd] +def get_option_value(line): + patt = re.compile(r'^\s+(?P