- name: Backup MikroTik config (text export only) hosts: mikrotik_routers gather_facts: no vars: backup_dir: /opt/mikrotik_backups/ tasks: # ---------------------------- # Ensure local backup directory # ---------------------------- - name: Ensure local backup directory exists ansible.builtin.file: path: "{{ backup_dir }}" state: directory mode: "0755" delegate_to: localhost # ---------------------------- # Get router identity # ---------------------------- - name: Get router identity community.routeros.command: commands: /system identity print register: identity_raw - name: Parse router name set_fact: router_name: "{{ identity_raw.stdout[0].split(': ')[1] | trim }}" # ---------------------------- # Timestamp # ---------------------------- - name: Get timestamp ansible.builtin.command: date +%Y-%m-%d_%H-%M-%S register: date_out delegate_to: localhost - name: Set timestamp fact set_fact: ts: "{{ date_out.stdout }}" # ---------------------------- # Export config (stable for diff) # ---------------------------- - name: Export router config community.routeros.command: commands: /export terse show-sensitive register: export_cfg # ---------------------------- # Save export locally # ---------------------------- - name: Save export locally ansible.builtin.copy: content: "{{ export_cfg.stdout[0] }}" dest: "{{ backup_dir }}/{{ router_name }}-{{ ts }}.rsc" delegate_to: localhost