Community discussions

MikroTik App
 
User avatar
Chaosphere64
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Wed Aug 10, 2016 10:19 pm

Config backup with Ansible fetch module

Fri Nov 11, 2022 9:20 pm

Hi everyone,

I am trying to setup a simple ansible script using the ansible.builtin.fetch module.
  • The ansible setup and access to my MikroTik device work fine.
  • Triggering the creation of a .backup and a .rsc file work fine.
  • Fetching the files from the MikroTik device to my linux box does NOT work.
Playbook:
---
# tasks for mtk-backup
- set_fact: time="{{lookup('pipe','date \"+%Y-%m-%d-%H-%M\"')}}"

- name: "Starting ROS System Backup"
  community.routeros.command:
    commands: /system backup save name {{inventory_hostname}}

- name: "Starting ROS Configuration Backup"
  community.routeros.command:
    commands: /export show-sensitive file={{inventory_hostname}}

- name: "Copying ROS System Backup to Local Host"
  ansible.builtin.fetch:
    src: /{{inventory_hostname}}.backup
    dest: ~/backup/mikrotik/{{inventory_hostname}}-{{time}}.backup

- name: "Copying ROS Configuation Backup to Local Host"
  ansible.builtin.fetch:
    src: /{{inventory_hostname}}.rsc
    dest: ~/backup/mikrotik/{{inventory_hostname}}-{{time}}.rsc
The error message is:
TASK [mtk-backup : Copying ROS System Backup to Local Host] *****************************************************************************************
fatal: [MikroTik-RO]: FAILED! => {"changed": false, "msg": "file not found: /MikroTik-RO.backup"}
*The file MikroTik-RO.backup is created running this playbook and exists in the root dir when checking the file list.

Has anyone (successfully) tried to fetch files from a MikroTik device using this ansible module?

Thanks!
 
pescobar
just joined
Posts: 2
Joined: Sat Nov 28, 2015 7:37 pm

Re: Config backup with Ansible fetch module

Tue Dec 13, 2022 12:53 pm

You have to use module ansible.netcommon.net_get. You can find the docs in https://docs.ansible.com/ansible/latest ... odule.html . Be aware you need "pip install scp" in the ansible control host.

Example:
    - name: "test"
      ansible.netcommon.net_get:
        src: "test1.rsc.backup"
        dest: "./test1.rsc.backup"
 
gzgenm
just joined
Posts: 4
Joined: Sun Oct 07, 2018 7:09 pm

Re: Config backup with Ansible fetch module

Wed Oct 11, 2023 6:22 pm

works only with
ansible_network_cli_ssh_type=paramiko

or there are corrupted files or timeout / incorrect scp params errors

Who is online

Users browsing this forum: No registered users and 10 guests