I know that I can't combine state transitions with a continue statement.
I'm trying to parse network configuration with ansible where the only clear end of row its the beginning of the next one.
For example I want to parse configs like follows:
line vty 0 4
exec-timeout 30 0
authorization exec MIRADIUS
accounting connection MIRADIUS
accounting exec MIRADIUS
login authentication MIRADIUS
line vty 5 16
access-class 95 in vrf-also
exec-timeout 30 0
authorization exec MIRADIUS
accounting connection MIRADIUS
accounting exec MIRADIUS
login authentication MIRADIUS
history size 25
transport input ssh
line vty 15 116
access-class 95 in
exec-timeout 30 0
authorization exec MIRADIUS
accounting connection MIRADIUS
accounting exec MIRADIUS
login authentication MIRADIUS
history size 25
Template I'm using:
Value Required LINE (\d+\s+\d+)
Value vtyAcl (\d+|\w+)
Value aclDir (\w+)
Value vrfAlso (\w+-\w+)
Start
^\s+access-class\s+${vtyAcl}\s+${aclDir}\s+${vrfAlso}.*$$
^\s+access-class\s+${vtyAcl}\s+${aclDir}.*$$
^line vty ${LINE}.*$$ -> Continue.Record
So the only certain way I have to know I'm done with the vty 0 4 for example is that the vty 5 16 starts.
so, it is possible to keep continue with the line in order to save the new vty? Currently my template is saving the config of previous row in the nextone. I have no way to know the which will be the lasts lines possibilities.
Current result:
[
{
"LINE": "0 4",
"aclDir": "",
"vrfAlso": "",
"vtyAcl": ""
},
{
"LINE": "5 16",
"aclDir": "",
"vrfAlso": "",
"vtyAcl": ""
},
{
"LINE": "15 116",
"aclDir": "in",
"vrfAlso": "vrf-also",
"vtyAcl": "95"
}
]
Desired Result:
[
{
"LINE": "0 4",
"aclDir": "",
"vrfAlso": "",
"vtyAcl": ""
},
{
"LINE": "5 16",
"aclDir": "in",
"vrfAlso": "vrf-also",
"vtyAcl": "95"
},
{
"LINE": "15 116",
"aclDir": "in",
"vrfAlso": "",
"vtyAcl": "95"
}
]
UPDATE: Here the update with solution for this particular issue. Thanks.
Value Required LINE (\d+\s+\d+)
Value vtyAcl (\d+|\w+)
Value aclDir (\w+)
Value vrfAlso (\w+-\w+)
Start
^line vty -> Continue.Record
^\s+access-class\s+${vtyAcl}\s+${aclDir}\s+${vrfAlso}.*$$
^\s+access-class\s+${vtyAcl}\s+${aclDir}.*$$
^line vty ${LINE}.*$$