mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
0e0e5097a9
commit
78ed0cadea
1 changed files with 41 additions and 38 deletions
|
@ -180,52 +180,56 @@ def get_ntp_source(module):
|
|||
def get_ntp_peer(module):
|
||||
command = 'show run | inc ntp.(server|peer)'
|
||||
ntp_peer_list = []
|
||||
ntp = execute_show_command(
|
||||
response = execute_show_command(
|
||||
command, module, command_type='cli_show_ascii')
|
||||
if ntp:
|
||||
ntp = ntp[0]
|
||||
|
||||
ntp_regex = (
|
||||
".*ntp\s(server\s(?P<address>\S+)|peer\s(?P<peer_address>\S+))"
|
||||
"\s*((?P<prefer>prefer)\s*)?(use-vrf\s(?P<vrf_name>\S+)\s*)?"
|
||||
"(key\s(?P<key_id>\d+))?.*"
|
||||
if response:
|
||||
if isinstance(response, list):
|
||||
ntp = response[0]
|
||||
else:
|
||||
ntp = response
|
||||
if ntp:
|
||||
ntp_regex = (
|
||||
".*ntp\s(server\s(?P<address>\S+)|peer\s(?P<peer_address>\S+))"
|
||||
"\s*((?P<prefer>prefer)\s*)?(use-vrf\s(?P<vrf_name>\S+)\s*)?"
|
||||
"(key\s(?P<key_id>\d+))?.*"
|
||||
)
|
||||
|
||||
split_ntp = ntp.splitlines()
|
||||
for peer_line in split_ntp:
|
||||
ntp_peer = {}
|
||||
try:
|
||||
peer_address = None
|
||||
vrf_name = None
|
||||
prefer = None
|
||||
key_id = None
|
||||
match_ntp = re.match(ntp_regex, peer_line, re.DOTALL)
|
||||
group_ntp = match_ntp.groupdict()
|
||||
split_ntp = ntp.splitlines()
|
||||
for peer_line in split_ntp:
|
||||
ntp_peer = {}
|
||||
try:
|
||||
peer_address = None
|
||||
vrf_name = None
|
||||
prefer = None
|
||||
key_id = None
|
||||
match_ntp = re.match(ntp_regex, peer_line, re.DOTALL)
|
||||
group_ntp = match_ntp.groupdict()
|
||||
|
||||
address = group_ntp["address"]
|
||||
peer_address = group_ntp['peer_address']
|
||||
prefer = group_ntp['prefer']
|
||||
vrf_name = group_ntp['vrf_name']
|
||||
key_id = group_ntp['key_id']
|
||||
address = group_ntp["address"]
|
||||
peer_address = group_ntp['peer_address']
|
||||
prefer = group_ntp['prefer']
|
||||
vrf_name = group_ntp['vrf_name']
|
||||
key_id = group_ntp['key_id']
|
||||
|
||||
if prefer is not None:
|
||||
prefer = 'enabled'
|
||||
else:
|
||||
prefer = 'disabled'
|
||||
if prefer is not None:
|
||||
prefer = 'enabled'
|
||||
else:
|
||||
prefer = 'disabled'
|
||||
|
||||
if address is not None:
|
||||
peer_type = 'server'
|
||||
elif peer_address is not None:
|
||||
peer_type = 'peer'
|
||||
address = peer_address
|
||||
if address is not None:
|
||||
peer_type = 'server'
|
||||
elif peer_address is not None:
|
||||
peer_type = 'peer'
|
||||
address = peer_address
|
||||
|
||||
args = dict(peer_type=peer_type, address=address, prefer=prefer,
|
||||
vrf_name=vrf_name, key_id=key_id)
|
||||
args = dict(peer_type=peer_type, address=address, prefer=prefer,
|
||||
vrf_name=vrf_name, key_id=key_id)
|
||||
|
||||
ntp_peer = dict((k, v) for k, v in args.items())
|
||||
ntp_peer_list.append(ntp_peer)
|
||||
except AttributeError:
|
||||
ntp_peer_list = []
|
||||
ntp_peer = dict((k, v) for k, v in args.items())
|
||||
ntp_peer_list.append(ntp_peer)
|
||||
except AttributeError:
|
||||
ntp_peer_list = []
|
||||
|
||||
return ntp_peer_list
|
||||
|
||||
|
@ -424,4 +428,3 @@ def main():
|
|||
from ansible.module_utils.basic import *
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
Loading…
Reference in a new issue