Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"delete" lines which only delete candidate config shouldn't be ignored #532

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/config_delete_filter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- In junos_config, "delete" lines which only delete candidate config lines are no longer ignored.
16 changes: 14 additions & 2 deletions plugins/modules/junos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,20 @@ def filter_delete_statements(module, candidate):
config = to_native(match.text, encoding="latin-1")

modified_candidate = candidate[:]
for index, line in reversed(list(enumerate(candidate))):
if line.startswith("delete"):
for index, line in list(enumerate(candidate)):
if not line.startswith("delete"):
continue
re_match_set = re.compile("^set" + re.escape(line[6:]) + "($| )")
# Remove candidate set config lines which are later removed.
for index2 in range(0, index):
if re_match_set.match(candidate[index2]):
# We can't just remove the element, that would mess up the indexing.
modified_candidate[index2] = None

for index, line in reversed(list(enumerate(modified_candidate))):
if line is None:
del modified_candidate[index]
elif line.startswith("delete"):
newline = re.sub("^delete", "set", line)
if newline not in config:
del modified_candidate[index]
Expand Down
Loading