Config backup with Ansible fetch module

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!

You have to use module ansible.netcommon.net_get. You can find the docs in https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/net_get_module.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"

works only with
ansible_network_cli_ssh_type=paramiko

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