backup_mikrotik.yml
---
- name: Backup Mikrotik
hosts: mikrotik
gather_facts: false
vars:
backup_dir: "/home/addansible/mikrotik_backup/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
inventory
[mikrotik]
ip-адрес mikrotik
[mikrotik:vars]
ansible_user=user1 (пользователь mikrotik)
ansible_password=user1 (пароль mikrotik)
ansible_connection=ansible.netcommon.network_cli
ansible_network_ok=community.routeros.routeros
ansible_python_interpreter=/usr/local/lib/python3.9
ansible_command_timeout=120
requirements.yml
---
collections:
- name: community.routeros
Для запуска
ansible-playbook backup_mikrotik.yml -i inventory
Ссылка на репозиторий в GitHub