cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1825
Views
10
Helpful
2
Replies

ansible palybook to backup APIC configuration

fakrulalam
Level 1
Level 1

Hi,

 

Is there any ansible playbook to backup APIC? I can see "aci_config_snapshot" module; but not sure whether it's all we need to backup and where able to restore it?

 

Thanks

Fakrul

2 Replies 2

Claudia de Luna
Spotlight
Spotlight

Hi @fakrulalam,

 

You are on the right track with the aci_config_snapshot module.

 

I do have to ask why not set up a daily backup and export?

 

Thats one of the first things I do when building out a fabric and it is important to get the backup off the fabric just in case something does happen to your controllers.

You can use the companion aci_config_rollback module to roll back to a snapshot but I think you may be looking for a full backup and restore and if so I would suggest setting up your fabric to do periodic backups off fabric and should anything happen to your fabric you can use the import option on the APICs.   In general that is the DR plan and for daily operations I recommend using the snapshots.

 

Below is a quick example of a playbook using the snapshot module.

 

---
###############################################################################
# This playbook executes configuration snapshots using the Ansible
# aci_config_snapshot module
#
#
# EXECUTION:
# ansible-playbook -i hosts aci_config_snapshot.yml
###############################################################################
- name: ACI Configuration Snapshot
  hosts: aci
  gather_facts: no


  tasks:
# Using set_facts rather than vars so that these variables are available across tasks
  - set_fact:
      aci_user: admin
      aci_pwd: ciscopsdt
      aci_host: sandboxapicdc.cisco.com

  - name: Query Snapshots Before Creating a new Snapshot
    aci_config_snapshot:
      host: "{{ aci_host }}"
      username: "{{ aci_user }}"
      password: "{{ aci_pwd }}"
      validate_certs: no
      state: query
    delegate_to: localhost
    register: query_result


  - name: List Snapshots Before new snapshot creation
    debug:
      msg: "{{ item.configSnapshot.attributes.fileName }}"
    with_items: "{{ query_result.current }}"

  - name: Create a snapshot of ACI "{{ aci_host}}"
    aci_config_snapshot:
      host: "{{ aci_host }}"
      username: "{{ aci_user }}"
      password: "{{ aci_pwd }}"
      validate_certs: no
      timeout: 90
      state: present
      export_policy: GDL_ConfigExportPolicy
      include_secure: yes
      max_count: 10
      description: GDL_Fabric_Snapshot
    delegate_to: localhost
    register: aci_snapshot

  - name: Query Snapshots After Creating a new Snapshot
    aci_config_snapshot:
      host: "{{ aci_host }}"
      username: "{{ aci_user }}"
      password: "{{ aci_pwd }}"
      validate_certs: no
      state: query
    delegate_to: localhost
    register: query_result

  - name: List Snapshots After new snapshot creation
    debug:
      msg: "{{ item.configSnapshot.attributes.fileName }}"
    with_items: "{{ query_result.current }}"

peterzhang
Level 1
Level 1

Snapshots are NOT meant to be used for backup purpose, they are only meant to be used for "rollback" during a change. Hence the Ansible module is used for you to incorporate it with other automation that you do before and after the change, hence it's more like an orchestration.

 

The ACI configuration export + scheduler is what you should use for daily backup

 

You can't restore full configuration from snapshots

Review Cisco Networking for a $25 gift card

Save 25% on Day-2 Operations Add-On License