Very simple and easy Ansible playbook to configure banner text on Cisco devices and save it automatic to start-config.
You can use one of these values {login, exec, motd, incoming and slip-ppp}, on line 17.
- Create an empty YAML file and name it banner.yaml with below codes:
# @author [Hawar Koyi] # @email [hawar.koy@gmail.com] # @create date 2021-07-09 01:15 # @desc [Automation - Configure the login banner] # @doc from Ansible [https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_banner_module.html] --- - name: Configure the login banner hosts: Cisco connection: network_cli gather_facts: false tasks: - name: Add configure the login banner ios_banner: #You can change below value to (motd, login, incoming or slip-ppp) banner: exec text: | ####################################################### # # # You have successfully entered this system # # $(hostname) on line $(line). Be advised your # # action are logged and audits are performed # # daily. If you have any questions contact the # # system administrator at +47 xx xx xx xx, # # email admin'at'yourdomain.net. # # # # Thank you # # # # Your name # # Network Administrator # # $(domain) # # # ####################################################### state: present #Tasks that save running-config to start-config when modified. - name: save running to start-config when modified ios_config: #You can change below value to (always,never or changed) save_when: modified #End of codes
2. Create an empty text file and name it hosts with devices IP-addresses and the defaults values.
As you can see I only added one device, otherwise you can add more than one device, if they have the same username and password.[Cisco] Router-1-home ansible_host=192.168.10.38 [Cisco:vars] ansible_connection=network_cli ansible_network_os=ios ansible_user=cisco ansible_password=cisco ansible_become=yes ansible_become_method=enable ansible_become_password=cisco
ansible_password: Device SSH password
ansible_become_password: Device enable password3. Run this command:
ansible-playbook -i hosts banner.yaml
Additional, watch my created video about this Ansible playbook.