Wednesday, September 16, 2020

Backing up Mikrotik routers with Ansible - help needed

I am a long time sysadmin who in the past year has done more and more network admin work. I decided to start backing up Cisco Switch configs with Ansible last week and have that working, mostly because there is lots to google on the subject. My boss LOVES the project and would like me to do the same with Mikrotik routers. I enabled SSH to one router and am trying a host file and playbook that I have found online and cannot get any combination of values to work. Any help on the subject would be greatly appreciated. Below are the technical details I am working with.

Ansible VM Ubuntu Desktop 20

Hosts file I am working with (Cisco switches are backing up normally.

[Switches:vars]

ansible_python_interpreter=/bin/python3

ansible_connection=local

device_type=cisco_ios

ansible_user=user

ansible_password=password

[Switches]

Core2 ansible_host=xxx.xxx.xxx.xxx

Core3 ansible_host=xxx.xxx.xxx.xxx

Core ansible_host=xxx.xxx.xxx.xxx

[mikrotik:vars]

ansible_python_interpreter=/bin/python3

ansible_connection=local

ansible_network_os=routeros

ansible_user=user

ansible_password=password

[mikrotik]

Main ansible_host=xxx.xxx.xxx.xxx

Cisco playbook that works

---

## Playbook to get system time and append it to backup files

- hosts: localhost

tasks:

- name: Get ansible date/time facts

setup:

filter: "ansible_date_time"

gather_subset: "!all"

- name: Store DTG as fact

set_fact:

DTG: ""

- name: Create Directory

file:

path: ~/etc/ansible/Backups/

state: directory

run_once: true

- hosts: Switches

tasks:

- name: Backup Catalyst Switch

ios_config:

backup: yes

backup_options:

filename: "--config.txt"

dir_path: /etc/ansible/Backups/

I have tried to piece together a Mikrotik playbook, but get failures when running.

---

## Playbook to get system time and append it to backup files

- hosts: localhost

tasks:

- name: Get ansible date/time facts

setup:

filter: "ansible_date_time"

gather_subset: "!all"

- name: Store DTG as fact

set_fact:

DTG: ""

- name: Create Directory

file:

path: ~/etc/ansible/Backups/

state: directory

run_once: true

- hosts: mikrotik

gather_facts: no

tasks:

- name: Performing backup of Mikrotik to local storage

raw: /system backup save name

- name: Exporting current configuration to text

raw: /export file=/etc/ansible/Backups/

The error in Ansible is pasted below (without the device name)

fatal: [Main]: FAILED! => {"changed": true, "msg": "non-zero return code", "rc": 127, "stderr": "/bin/sh: 1: /system: not found\n", "stderr_lines": ["/bin/sh: 1: /system: not found"], "stdout": "", "stdout_lines": []}

Again, any help is greatly appreciated!



No comments:

Post a Comment