�
�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
m Z d d � Z
d
� Z d � Z e d � Z e d k r� e � n d S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust communityt supported_bys�
---
module: nclu
version_added: "2.3"
author: "Cumulus Networks (@isharacomix)"
short_description: Configure network interfaces using NCLU
description:
- Interface to the Network Command Line Utility, developed to make it easier
to configure operating systems running ifupdown2 and Quagga, such as
Cumulus Linux. Command documentation is available at
U(https://docs.cumulusnetworks.com/cumulus-linux/System-Configuration/Network-Command-Line-Utility-NCLU/)
options:
commands:
description:
- A list of strings containing the net commands to run. Mutually
exclusive with I(template).
template:
description:
- A single, multi-line string with jinja2 formatting. This string
will be broken by lines, and each line will be run through net.
Mutually exclusive with I(commands).
commit:
description:
- When true, performs a 'net commit' at the end of the block.
Mutually exclusive with I(atomic).
default: false
type: bool
abort:
description:
- Boolean. When true, perform a 'net abort' before the block.
This cleans out any uncommitted changes in the buffer.
Mutually exclusive with I(atomic).
default: false
type: bool
atomic:
description:
- When true, equivalent to both I(commit) and I(abort) being true.
Mutually exclusive with I(commit) and I(atomic).
default: false
type: bool
description:
description:
- Commit description that will be recorded to the commit log if
I(commit) or I(atomic) are true.
default: "Ansible-originated commit"
s#
- name: Add two interfaces without committing any changes
nclu:
commands:
- add int swp1
- add int swp2
- name: Modify hostname to Cumulus-1 and commit the change
nclu:
commands:
- add hostname Cumulus-1
commit: true
- name: Add 48 interfaces and commit the change.
nclu:
template: |
{% for iface in range(1,49) %}
add int swp{{iface}}
{% endfor %}
commit: true
description: "Ansible - add swps1-48"
- name: Fetch Status Of Interface
nclu:
commands:
- show interface swp1
register: output
- name: Print Status Of Interface
debug:
var: output
- name: Fetch Details From All Interfaces In JSON Format
nclu:
commands:
- show interface json
register: output
- name: Print Interface Details
debug:
var: output["msg"]
- name: Atomically add an interface
nclu:
commands:
- add int swp1
atomic: true
description: "Ansible - add swp1"
- name: Remove IP address from interface swp1
nclu:
commands:
- del int swp1 ip address 1.1.1.1/24
- name: Configure BGP AS and add 2 EBGP neighbors using BGP Unnumbered
nclu:
commands:
- add bgp autonomous-system 65000
- add bgp neighbor swp51 interface remote-as external
- add bgp neighbor swp52 interface remote-as external
commit: true
- name: Configure BGP AS and Add 2 EBGP neighbors Using BGP Unnumbered via Template
nclu:
template: |
{% for neighbor in range(51,53) %}
add bgp neighbor swp{{neighbor}} interface remote-as external
add bgp autonomous-system 65000
{% endfor %}
atomic: true
- name: Check BGP Status
nclu:
commands:
- show bgp summary json
register: output
- name: Print BGP Status In JSON
debug:
var: output["msg"]
s
changed:
description: whether the interface was changed
returned: changed
type: bool
sample: True
msg:
description: human-readable report of success or failure
returned: always
type: str
sample: "interface bond0 config updated"
( t
AnsibleModulec C` s] | j d | � \ } } } | s: d | k s: d | k rS | j d | pL | � n t | � S( s$ Run a command, catch any nclu errorss /usr/bin/net %st ERRORt msg( t run_commandt fail_jsont str( t modulet commandt errmsgt _rct outputt _err( ( sH /usr/lib/python2.7/site-packages/ansible/modules/network/cumulus/nclu.pyt command_helper� s c C` s\ t | d d � } d } d } | | k rR | j | � d } | j | d � } n | j � S( s* Check the pending diff of the nclu buffer.t pendingsK Error in pending config. You may want to view `net pending` on this target.s0 net add/del commands since the last 'net commit's [94mi t ( R t splitt replacet strip( R R t
delimeter1t color1( ( sH /usr/lib/python2.7/site-packages/ansible/modules/network/cumulus/nclu.pyt
check_pending� s c C` sg t } g } | r | } n | r0 | j � } n t } | }
| sH | r` t } | r` t }
q` n |
rv t | d � n t | � } g } x@ | D]8 }
|
j � r� | t | |
j � d |
� g 7} q� q� Wd j | � } t | � } | | k r� t } n t } | r]t | d | � } d | k r<t } t | d � q]t | d � d k r]t } q]n | | f S( Nt aborts Failed on line %ss
s commit description '%s's commit ignoreds show commit lastR ( t Falset
splitlinest TrueR R R t join( R t command_listt command_stringt committ atomicR t descriptiont _changedt commandst do_committ do_abortt beforet output_linest lineR t aftert result( ( sH /usr/lib/python2.7/site-packages/ansible/modules/network/cumulus/nclu.pyt run_nclu� s@
* c
C` s� t d t d t d t d d � d t d t d d � d t d t d d d d
� d t d t d d d t � d
t d t d d d t � d t d t d d d t � � d d d d g � } | j j d d � } | j j d d � } | j j d
� } | j j d � } | j j d � } | j j d � } t | | | | | | | � \ } } | sl| j d | d | � n | r�i | d 6| d 6Sd S( Nt
argument_specR( t requiredt typet listt templateR
R&