I've written a script that does an API call to our golden config site, pulls down only the ACLs, and spits them out into a Jinja2 file to be imported into a base config. This was all done via regex.
What i'm trying to do is add an exclamation point on the bottom of each ACL if one doesn't exist, or remove any extra lines if they do exist below this exclamation point.
Here is what I have, and while it may work, I sense it can run into issues so i'm looking for a cleaner version (figure an ACL is assigned to the variable 'acl', and is currently a string)
acl = acl.splitlines()
if acl[-1] != '!':
acl.append('!')
Any help would be appreciated. My concern with above is if there's an empty line after an '!' it would still add it, and maybe some others that I cannot think of at the moment.