mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
Fix interfaces_file for proper file contents (#37818)
The generated file was completely unusable by the system therefore the fix which ensures that diffing the file prior to changes and after only shows diffs Furthermore the code did not work for Python 3.6 > f.writelines(to_bytes(lines, errors='surrogate_or_strict')) E TypeError: a bytes-like object is required, not 'int' The other modifications (lambda variable renaming) is to comply with default flake8 rules
This commit is contained in:
committed by
John R Barker
parent
710db82930
commit
612d0d6634
@@ -290,11 +290,11 @@ def setInterfaceOption(module, lines, iface, option, raw_value, state):
|
||||
if option in ["pre-up", "up", "down", "post-up"] and value is not None and value != "None":
|
||||
for target_option in filter(lambda i: i['value'] == value, target_options):
|
||||
changed = True
|
||||
lines = list(filter(lambda l: l != target_option, lines))
|
||||
lines = list(filter(lambda ln: ln != target_option, lines))
|
||||
else:
|
||||
changed = True
|
||||
for target_option in target_options:
|
||||
lines = list(filter(lambda l: l != target_option, lines))
|
||||
lines = list(filter(lambda ln: ln != target_option, lines))
|
||||
else:
|
||||
module.fail_json(msg="Error: unsupported state %s, has to be either present or absent" % state)
|
||||
|
||||
@@ -322,7 +322,7 @@ def write_changes(module, lines, dest):
|
||||
|
||||
tmpfd, tmpfile = tempfile.mkstemp()
|
||||
f = os.fdopen(tmpfd, 'wb')
|
||||
f.writelines(to_bytes(lines, errors='surrogate_or_strict'))
|
||||
f.write(to_bytes(''.join(lines), errors='surrogate_or_strict'))
|
||||
f.close()
|
||||
module.atomic_move(tmpfile, os.path.realpath(dest))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user