�
�Udac @` s� d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d Z d
Z d d l
Z
d d l m Z d d
l
m Z m Z m Z m Z d d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z e d k r� e � n d S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust networkt supported_bysT
---
module: nxos_ntp
extends_documentation_fragment: nxos
version_added: "2.2"
short_description: Manages core NTP configuration.
description:
- Manages core NTP configuration.
author:
- Jason Edelman (@jedelman8)
options:
server:
description:
- Network address of NTP server.
peer:
description:
- Network address of NTP peer.
key_id:
description:
- Authentication key identifier to use with
given NTP server or peer or keyword 'default'.
prefer:
description:
- Makes given NTP server or peer the preferred
NTP server or peer for the device.
choices: ['enabled', 'disabled']
vrf_name:
description:
- Makes the device communicate with the given
NTP server or peer over a specific VRF or
keyword 'default'.
source_addr:
description:
- Local source address from which NTP messages are sent
or keyword 'default'
source_int:
description:
- Local source interface from which NTP messages are sent.
Must be fully qualified interface name or keyword 'default'
state:
description:
- Manage the state of the resource.
default: present
choices: ['present','absent']
s�
# Set NTP Server with parameters
- nxos_ntp:
server: 1.2.3.4
key_id: 32
prefer: enabled
host: "{{ inventory_hostname }}"
username: "{{ un }}"
password: "{{ pwd }}"
s�
proposed:
description: k/v pairs of parameters passed into module
returned: always
type: dict
sample: {"address": "192.0.2.2", "key_id": "48",
"peer_type": "server", "prefer": "enabled",
"source": "192.0.2.3", "source_type": "source"}
existing:
description:
- k/v pairs of existing ntp server/peer
returned: always
type: dict
sample: {"address": "192.0.2.2", "key_id": "32",
"peer_type": "server", "prefer": "enabled",
"source": "ethernet2/1", "source_type": "source-interface"}
end_state:
description: k/v pairs of ntp info after module execution
returned: always
type: dict
sample: {"address": "192.0.2.2", "key_id": "48",
"peer_type": "server", "prefer": "enabled",
"source": "192.0.2.3", "source_type": "source"}
updates:
description: command sent to the device
returned: always
type: list
sample: ["ntp server 192.0.2.2 prefer key 48",
"no ntp source-interface ethernet2/1", "ntp source 192.0.2.3"]
changed:
description: check to see if a change was made on the device
returned: always
type: bool
sample: true
N( t
AnsibleModule( t
check_argst load_configt nxos_argument_spect run_commandst cli_showc C` s? d | k r d } n d } i | d 6| d 6g } t | | � S( Ns show runt jsont textt commandt output( R ( R t modulet command_typeR t commands( ( sI /usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_ntp.pyt execute_show_commandq s
c C` sG g } x: | D]2 } t | t � r2 | j | � q
| j | � q
W| S( N( t
isinstancet listt extendt append( t
command_listst flat_command_listR ( ( sI /usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_ntp.pyt flatten_list~ s
c C` s� d } d } d } t | | d d �} | r� y= d | d k rI d } n d } | d j � d j � } Wq� t t f k
r� d } d } q� Xn | | f S( Ns show run | inc ntp.sourceR t cli_show_asciit interfacei s source-interfacet sourcei ( t NoneR t splitt lowert AttributeErrort
IndexError( R t source_typeR R R ( ( sI /usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_ntp.pyt get_ntp_source� s
c C` s� d } g } t | | d d �} | r�t | t � rC | d } n | } | r�d } | j � } xP| D]E} d | k r� qh n i } y
d } d }
d } d } t j | | t j � }
|
j � } | d } | d } | d
} | d }
| d } | d k rd
} n d } | d k r'd } n | d k rBd } | } n t d | d | d
| d |
d | � } t d � | j
� D� � } | j | � Wqh t k
r�g } qh Xqh Wq�n | S( Ns show run | inc ntp.(server|peer)R R i s� .*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+))?.*s access-groupt defaultt addresst peer_addresst prefert vrf_namet key_idt enabledt disabledt servert peert peer_typec s` s! | ] \ } } | | f Vq d S( N( ( t .0t kt v( ( sI /usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_ntp.pys <genexpr>� s (
R R R t
splitlinesR t ret matcht DOTALLt groupdictt dictt itemsR R# ( R R t
ntp_peer_listt responset ntpt ntp_regext split_ntpt peer_linet ntp_peerR) R+ R* R, t match_ntpt group_ntpR( R1 t args( ( sI /usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_ntp.pyt get_ntp_peer� sT
c C` s� i } g } t | � } x; | D]3 } | d | k rE | j | � q | j | � q Wt | � \ } } | d k r� | d k r� | | d <| | d <n | | f S( NR( R% R ( RF t updateR R&