Ansible ile Cisco Switch Configuration Backup

Ansible ile Cisco Switch Configuration Backup
Ansible cisco switch config backup
Ansible Cisco switch configurasyon backup
Cisco config backup
Ansible ile Cisco Siwtch konfigürasyon yedeği alma

Ansible ile Cisco Switch Configuration Backup Playbook

Switchlerinizin konfigurasyon yedeklerini ansible ile bir tftp server’a almak için aşağıdaki playbook’u yazmanız yeterlelidir.

Playbook’u yazmadan önce /etc/ansible dizininin altındaki hosts dosyanızın içine konfigürasyon yedeğini almak istediğiniz switchlerinizin ip adreslerini yazmanız gerekmektedir. Örnek hosts dosyası aşağıdaki gibi olabilir.

[cisco]
Switch-1 ansible_host=10.100.0.1
Switch-2 ansible_host= 10.100.0.2
Switch-3 ansible_host= 10.100.0.2
Switch-4 ansible_host= 10.100.0.3
Switch-5 ansible_host= 10.100.0.5

hosts dosyanızın içine yurkarıdaki gibi switch bilgileriniz ekledikten sonra aşağıdaki playbook’u /etc/ansible/playbook dizininin altına yazabilirsiniz.

---
#Bu kısımda varsa daha önce /tftpboot dizinine alınan yedekler onları başka bir dizine taşıyoyoruz.
- hosts: localhost
connection: local
tasks:
- name: move old config backups file
shell: |
touch /tftpboot/localhost.conf
mv /tftpboot/*.conf /tftpboot/config_backups/
tar -cvzf /tftpboot/config_backups/switch_configs_{{ansible_date_time.date}}.tar.gz /tftpboot/config_backups/*.conf
rm /tftpboot/config_backups/*.conf

#Burada ise /tftpboot dizinine configurasyonların yedeğini alacağımız bir dosya oluşturuyoruz.

- hosts: cisco
connection: local
vars:
tasks:
- name: create file
shell: |
touch /tftpboot/{{ansible_host}}.conf
chmod 777 /tftpboot/{{ansible_host}}.conf
delegate_to: 127.0.0.1

#Bu kısımda switchlerimize login olup configurasyonlarını tftp serverimize gönderiyoruz.
- name: backup cisco runing config
ios_command:
authorize: yes
auth_pass: Switch_eneble_şifresi
commands:
- command: 'copy running-config tftp://TFTP_SERVER_IP_ADRESI/{{ansible_host}}.conf'
prompt: 'Address or name of remote host [****]?'
answer: "\n"
prompt: '[{{ansible_host}}.conf]?'
answer: "\n"
register: configcisco