AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Automate Mikrotik RouterOS Config Backups with Ansible — Video Tutorial

Learn how to automate configuration backups for Mikrotik RouterOS with Ansible. This guide includes a step-by-step Playbook example for seamless backups using SSH and file management.

Watch Video

Watch "Automate Mikrotik RouterOS Config Backups with Ansible" on YouTube

What You'll Learn

Full Tutorial Content

How to Backup Config on Mikrotik RouterOS with Ansible? Maintaining a backup copy of your network appliance configuration is a good practice for all IT Professionals. You could automate this process for Mikrotik RouterOS appliances using Ansible. I'm going to show you a live Playbook with some simple Ansible code. I'm Luca Berton and welcome to today's episode of Ansible Pilot. Ansible Backup Config on Mikrotik RouterOS > `community.routeros`: Modules for MikroTik RouterOS Let's talk about the Ansible collection `community.routeros`. The full name is `community.routeros`, which means that is an Ansible Network Collection designed to interact with Mikrotik RouterOS devices. It contains modules for MikroTik RouterOS. Links - [Community.Routeros](https://docs.ansible.com/ansible/latest/collections/community/routeros/index.html) ## Playbook How to Backup Config on Mikrotik RouterOS with Ansible Playbook. I'm going to show how to back up the current configuration of a Mikrotik RouterOS connecting via SSH protocol using the username and password credentials and save it to a file with the device name and timestamp. code - inventory ```ini [mikrotik] 192.168.88.2 [mikrotik:vars] ansible_user=luca ansible_password=mysecretpassword123 ansible_connection=ansible.netcommon.network_cli ansible_network_os=community.routeros.routeros ansible_python_interpreter=/usr/bin/python3 ansible_command_timeout=120 ``` - backup_mikrotik.yml ```yaml --- - name: Backup Mikrotik hosts: mikrotik gather_facts: false vars: backup_dir: "/home/luca/network/backup" tasks: - name: Export ansible.builtin.shell: >- sshpass -p '{{ ansible_password }}' ssh -o StrictHostKeyChecking=no {{ ansible_user }}@{{ inventory_hostname }} /export register: export delegate_to: localhost - name: Backup ansible.builtin.copy: content: "{{ export.stdout }}" dest: "{{ backup_dir }}/{{ inventory_hostname }}_config.{{ lookup('pipe', 'date +%Y-%m-%d@%H:%M:%S') }}" when: export is defined delegate_to: localhost ``` - requirements.yml ```yaml --- collections: - name: community.routeros ``` requirements setup ```bash $ ansible-galaxy install -r requirements.yml Starting galaxy collection install process Process install dependency map Starting collection install process Downloading https://galaxy.ansible.com/download/community-routeros-2.0.0.tar.gz to /home/luca/.ansible/tmp/ansible-local-47086a9aez7_s/tmpqz_6puy_/community-routeros-2.0.0-hlve2za9 Installing 'community.routeros:2.0.0' to '/home/luca/.ansible/collections/ansible_collections/community/routeros' community.routeros:2.0.0 was installed successfully 'ansible.netcommon:3.0.0' is already installed, skipping. 'ansible.utils:2.6.1' is already installed, skipping. luca@luca01:~/network$ ansible-galaxy collection list /home/luca/.ansible/collections/ansible_collections Collection Version ------------------ ------- ansible.netcommon 3.0.0 ansi

About This Tutorial

Read the full written article: Automate Mikrotik RouterOS Config Backups with Ansible

Topics Covered

Related Video Tutorials