Below are the inventory and playbook files that I have come up with to backup Cambium cnMatrix switches using Ansible on a Linux server. Modify for your needs.

Inventory File <— This is where you are going to add your cnMatrix switches. Inventory files are common to Ansible and you will need this. I’m not going to dive into all the details of this file. Below should suffice for this project. This same inventory file could be renamed and used for other devices as well that support SSH.

[cnmatrix:vars]
ansible_connection=network_cli
ansible_network_os=ios
ansible_user=yourusername
ansible_password=yourpassword

[cnmatrix]
cnMatrix01 ansible_ssh_host=192.168.1.10 ansible_port=22
cnMatrix02 ansible_ssh_host=192.168.1.11 ansible_port=22

Playbook File <— This file is where all the commands will be configured to run against the inventory file. Below is the current playbook.yml that can backup a Cambium cnMatrix switch. This same type of configuration can also be used with Cisco, Juniper, etc, with slight modification.

---
- hosts: cnmatrix
  gather_facts: false

  tasks:
    - name: Create Directory named current date
      file:
        path: /cambium/cnMatrix/backups/{{ lookup('pipe', 'date +%m-%d-%Y') }}
        state: directory
      run_once: true

    - name: TFTP Backup
      ansible.netcommon.cli_command:
        command: copy running-config tftp://192.168.1.23/backups/cnMatrix/backups/{{ lookup('pipe', 'date +%m-%d-%Y') }}/{{ inventory_hostname }}_{{ lookup('pipe', 'date +%m-%d-%Y') }}.cfg

    - name: Check for backup files
      command: find /cambium/cnMatrix/backups/{{ lookup('pipe', 'date +%m-%d-%Y') }} -printf "%f\n"
      register: backup_files
      run_once: true

    - mail:
        host: 192.168.1.2
        port: 25
        from: root@somedomain.com
        to: you@somedomain.com
        subject: cnMatrix Backup Status
        body: ' "{{ backup_files.stdout }}" '
      when: backup_files.stdout
      run_once: true

This playbook creates a folder named the current date. Then the script logs in via SSH and invokes the copy TFTP command and places the backup in that folder. Then the script checks the backup files and it registers the name “backup_files” for the output. Finally the script emails the contents of the output(find command) showing each file in that directory(Basically a status email letting you know it was backed up).

So in the end with this playbook you’ll end up with a backup file in /backups/cambium/cnmatrix/01-06-24/cnmatrix_01-06-24.cfg

Run the playbook command: ansible-playbook -i inventory playbook.yml <— Put in a bash script and run as a CRON job.

Debug the playbook: ansible-playbook -i inventory playbook.yml -vvv

By Tim