diff options
author | Gary Rybak <grybak@arista.com> | 2016-02-10 17:21:24 -0700 |
---|---|---|
committer | Gary Rybak <grybak@arista.com> | 2016-02-10 17:21:24 -0700 |
commit | 373961da043fc33bd78a3f123092d201fed92bd8 (patch) | |
tree | bc508f971127d823b32473b7bfd219c6f97e6680 | |
parent | 3d4b5d165cc76c1fef1f604d77ff469e3bb0074a (diff) | |
download | ansible-modules-core-373961da043fc33bd78a3f123092d201fed92bd8.tar.gz |
Add filter to eos_template to remove configuration mode command
followed immediately by an exit command indented one level.
-rw-r--r-- | network/eos/eos_template.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/network/eos/eos_template.py b/network/eos/eos_template.py index 613a613e..51d7aeef 100644 --- a/network/eos/eos_template.py +++ b/network/eos/eos_template.py @@ -109,6 +109,8 @@ responses: sample: ['...', '...'] """ +import re + def compare(this, other): parents = [item.text for item in this.parents] for entry in other: @@ -188,6 +190,30 @@ def main(): commands = flatten(commands, list()) + # Filter out configuration mode commands followed immediately by an + # exit command indented by one level only, e.g. + # - route-map map01 permit 10 + # - exit + # + # Build a temporary list as we filter, then copy the temp list + # back onto the commands list. + temp = [] + ind_prev = 999 + count = 0 + for c in commands: + ind_this = c.count(' ') + if re.search(r"^\s*exit$", c) and ind_this == ind_prev + 1: + temp.pop() + count -= 1 + if count != 0: + ind_prev = temp[-1].count(' ') + continue + temp.append(c) + ind_prev = ind_this + count += 1 + + commands = temp + if commands: if not module.check_mode: commands = [str(c).strip() for c in commands] @@ -208,4 +234,3 @@ from ansible.module_utils.netcfg import * from ansible.module_utils.eos import * if __name__ == '__main__': main() - |