Untitled
Anonymous
Plain Text
09/18/2025 2:02 PM
3.6 KB
19
Indexable
Never
---
- name: FSOS Switch Backup and Configuration
hosts: fs_switches
gather_facts: no
vars:
backup_dir: /home/amrc-demopc/fs-fsos-backup/backups
tasks:
- name: Ensure local backup directory exists
ansible.builtin.file:
path: "{{ backup_dir }}"
state: directory
mode: '0755'
delegate_to: localhost
- name: Get current timestamp
ansible.builtin.command: date +%Y%m%d_%H%M%S
register: timestamp
delegate_to: localhost
run_once: true
- name: Backup running config using expect
ansible.builtin.expect:
command: >
ssh -oKexAlgorithms=+diffie-hellman-group14-sha1
-oHostKeyAlgorithms=+ssh-dss
-oPubkeyAcceptedAlgorithms=+ssh-dss
-oPubkeyAcceptedKeyTypes=+ssh-dss
-oMACs=+hmac-sha1
-oCiphers=+aes128-cbc,aes256-cbc,3des-cbc
-oStrictHostKeyChecking=no
admin@{{ ansible_host }}
responses:
'Password:': '{{ ansible_ssh_pass }}'
'FS#': 'show running-config'
timeout: 30
register: running_config_raw
delegate_to: localhost
- name: Extract config from expect output
ansible.builtin.set_fact:
running_config: "{{ running_config_raw.stdout | regex_replace('.*show running-config\\s*\\n', '') | regex_replace('FS#.*', '') }}"
- name: Get system version using expect
ansible.builtin.expect:
command: >
ssh -oKexAlgorithms=+diffie-hellman-group14-sha1
-oHostKeyAlgorithms=+ssh-dss
-oPubkeyAcceptedAlgorithms=+ssh-dss
-oPubkeyAcceptedKeyTypes=+ssh-dss
-oMACs=+hmac-sha1
-oCiphers=+aes128-cbc,aes256-cbc,3des-cbc
-oStrictHostKeyChecking=no
admin@{{ ansible_host }}
responses:
'Password:': '{{ ansible_ssh_pass }}'
'FS#': 'show version'
timeout: 30
register: version_info_raw
delegate_to: localhost
- name: Extract version from expect output
ansible.builtin.set_fact:
version_info: "{{ version_info_raw.stdout | regex_replace('.*show version\\s*\\n', '') | regex_replace('FS#.*', '') }}"
- name: Save running config to backup file
ansible.builtin.copy:
content: |
# FS FSOS Switch Configuration Backup
# Switch: {{ inventory_hostname }} ({{ ansible_host }})
# Date: {{ timestamp.stdout }}
# Generated by Ansible FSOS Backup Script
{{ running_config }}
dest: "{{ backup_dir }}/{{ inventory_hostname }}-config-{{ timestamp.stdout }}.cfg"
mode: '0644'
delegate_to: localhost
- name: Save system information to backup file
ansible.builtin.copy:
content: |
# FS FSOS System Information Backup
# Switch: {{ inventory_hostname }} ({{ ansible_host }})
# Date: {{ timestamp.stdout }}
=== SYSTEM VERSION ===
{{ version_info }}
dest: "{{ backup_dir }}/{{ inventory_hostname }}-system-{{ timestamp.stdout }}.txt"
mode: '0644'
delegate_to: localhost
- name: Display backup completion summary
ansible.builtin.debug:
msg: |
==========================================
FSOS BACKUP COMPLETED: {{ inventory_hostname }}
==========================================
Switch IP: {{ ansible_host }}
Timestamp: {{ timestamp.stdout }}
Files Created:
• {{ backup_dir }}/{{ inventory_hostname }}-config-{{ timestamp.stdout }}.cfg
• {{ backup_dir }}/{{ inventory_hostname }}-system-{{ timestamp.stdout }}.txt
==========================================Editor is loading...
Leave a Comment