
    Vh                         d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d dlmZ d dlmZmZ d	 Zd
 Zd Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona]  
module: nxos_banner
author: Trishna Guha (@trishnaguha)
short_description: Manage multiline banners on Cisco NXOS devices
description:
- This will configure both exec and motd banners on remote devices running Cisco NXOS.
  It allows playbooks to add or remove banner text from the active running configuration.
notes:
- Since responses from the device are always read with surrounding whitespaces stripped,
  tasks that configure banners with preceeding or trailing whitespaces will not be idempotent.
- Limited Support for Cisco MDS
version_added: 1.0.0
options:
  banner:
    description:
    - Specifies which banner that should be configured on the remote device.
    required: true
    choices:
    - exec
    - motd
    type: str
  multiline_delimiter:
    description: Specify the delimiting character than will be used for configuration.
    default: "@"
    type: str
  text:
    description:
    - The banner text that should be present in the remote device running configuration.
      This argument accepts a multiline string, with no empty lines. Requires I(state=present).
    type: str
  state:
    description:
    - Specifies whether or not the configuration is present in the current devices
      active running configuration.
    default: present
    choices:
    - present
    - absent
    type: str
extends_documentation_fragment:
- cisco.nxos.nxos
a  
- name: configure the exec banner
  cisco.nxos.nxos_banner:
    banner: exec
    text: |
      this is my exec banner
      that contains a multiline
      string
    state: present
- name: remove the motd banner
  cisco.nxos.nxos_banner:
    banner: motd
    state: absent
- name: Configure banner from file
  cisco.nxos.nxos_banner:
    banner: motd
    text: "{{ lookup('file', './config_partial/raw_banner.cfg') }}"
    state: present
z
commands:
  description: The list of configuration mode commands to send to the device
  returned: always
  type: list
  sample:
    - banner exec
    - this is my exec banner
    - that contains a multiline
    - string
N)to_text)AnsibleModule)load_configrun_commandsc                 .    d}||dg}t        | |      }|S )Ntext)commandoutput)r	   )moduler   formatcmdsr   s        j/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/nxos/plugins/modules/nxos_banner.pyexecute_show_commandr   q   s%    F623D&$'FM    c           	         t               }|j                  d   }d}|dk(  rm|j                  d      rZ|j                  d      dk(  sFt        j                  ||j                  d            s!|j                  d|j                  d   z         |S |dk(  rl| j                  d      |j                  d      k7  rId	|j                  d   d
|j                  d   d| d   d|j                  d   }|j                  |       |S )NstatezNexus.*Switchabsentr   zUser Access Verificationzno banner %sbannerpresentzbanner  multiline_delimiter
)listparamsgetrematchappend)wanthaver   commandsr   platform_regex
banner_cmds          r   map_obj_to_commandsr'   x   s    vHMM'"E$N88FXXf!;;xx(89OONV]]8-DDE O 
)	 0DHHV4D DMM(#MM/0LMM/0	

 	
#Or   c                    d| j                   d   z  }t        | |      d   }d|v r"| j                  d| j                   d   z         t        |t              r]t        |j                               }|g k7  r|d   }nd}t        |t              r7t        |j                               }|g k7  r|d   }nd}n|j                         }| j                   d   dd	}|r
||d
<   d|d<   |S )Nzshow banner %sr   r   zInvalid commandzTbanner: %s may not be supported on this platform.  Possible values are : exec | motd)msg r   )r   r   r   r   r   )r   r   	fail_json
isinstancedictr   valuesrstrip)r   r   r   objs       r   map_config_to_objr1      s    x!88G!&'215FF"fmmH%& 	 	

 &$fmmo&R<AYFFfd#&--/*F|]]8,x
@CF GJr   c                 z    | j                   d   }| j                   d   |rt        |      nd | j                   d   dS )Nr   r   r   )r   r   r   )r   r   )r   r   s     r   map_params_to_objr3      s=    == D--)!%4w' r   c            
         t        t        dddg      t               t        d      t        dddg	      
      } dg}t        | |d      }t               }ddi}|r||d<   t        |      }t	        |      }t        |||      }||d<   |rW|j                  sFt        ||d      }|r7|D ]2  }	|	st        |	t               r|	d   }
n|	}
d|
v sd|
v s't        ||       4 d|d<    |j                  di | y)z%main entry point for module executionTexecmotd)requiredchoices@)defaultr   r   )r:   r8   )r   r   r   r   )r   r   )r   )argument_specrequired_ifsupports_check_modechangedFwarningsr$   clierrorzmore than 40 lineszbuffer overflowedN )
r-   r   r   r3   r1   r'   
check_moder   r,   	exit_json)r;   r<   r   r?   resultr"   r#   r$   msgsitemerr_strs              r   mainrH      s"   TFF+;<V -9y(.CD	M 33K# F vHF%zV$DV$D"4v6H!F:  vx6D  :D%dD1&*:&6G&*G/7:>QU\>\'9: !yFvr   __main__)
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURNr   ansible.module_utils._textr   ansible.module_utils.basicr   Eansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxosr   r	   r   r'   r1   r3   rH   __name__rA   r   r   <module>rT      sj    A @ *)V(

 
 . 40@*Z zF r   