mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-22 14:01:42 -07:00
* When inserting a new rule in `insert_after_rule`, check if the old rule is the last rule, to avoid a list index out of range error when attempting to access the next rule. * Add a test for inserting a new rule after the last rule.
This commit is contained in:
parent
158b32cd7a
commit
98260f9884
2 changed files with 13 additions and 1 deletions
|
@ -483,7 +483,10 @@ def insert_after_rule(service, old_rule, new_rule):
|
|||
if (old_rule.rule_type == rule.rule_type and
|
||||
old_rule.rule_control == rule.rule_control and
|
||||
old_rule.rule_module_path == rule.rule_module_path):
|
||||
if (new_rule.rule_type != service.rules[index + 1].rule_type or
|
||||
if (index == len(service.rules) - 1):
|
||||
service.rules.insert(len(service.rules), new_rule)
|
||||
changed = True
|
||||
elif (new_rule.rule_type != service.rules[index + 1].rule_type or
|
||||
new_rule.rule_control !=
|
||||
service.rules[index + 1].rule_control or
|
||||
new_rule.rule_module_path !=
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue