AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 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 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", 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.
What You'll Learn
- How to Backup Config on Mikrotik RouterOS with Ansible?
- Ansible Backup Config on Mikrotik RouterOS
- Links
- code
- requirements setup
- execution
- before execution
- after execution
- Conclusion
- Related Articles
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
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 3 min
- Category: installation
Read the full written article: Automate Mikrotik RouterOS Config Backups with Ansible
Related Video Tutorials
- Automate Dell EMC DNOS 10 Backups with Ansible Playbook — Learn to automate the backup of Dell EMC DNOS 10 configurations with Ansible. This guide includes a practical Playbook example and setup instructions.
- Backup Dell EMC DNOS 6 Configs with Ansible Playbook — Discover how to automate Dell EMC DNOS 6 configuration backups with Ansible. This guide includes a Playbook example and setup instructions for efficient.
- Ansible synchronize Module: Rsync Files & Directories Between Hosts — Discover how to use Ansible synchronize module for efficient file backups with rsync. Learn practical steps and see real-world examples for Linux systems.
- UFW Allow Port with Ansible: Complete Firewall Management Guide (Ubuntu/Debian) — Manage UFW firewall rules with Ansible on Ubuntu and Debian. Allow ports, deny traffic, rate-limit SSH, configure web server and database firewalls, IPv6.
- Ansible firewalld Module: Open Firewall Ports on RHEL/CentOS (Examples) — How to manage firewall ports on RHEL, CentOS, and Fedora using Ansible firewalld module. Open ports, add services, manage zones, and make rules permanent.
- AI DevOps Ansible Community on Skool — Join Luca Berton's AI DevOps Ansible Community for top-tier training in Ansible, Kubernetes, and Terraform. Access 50+ hours of courses and career support!