Add mikrotikbackup_clean.yml
This commit is contained in:
59
mikrotikbackup_clean.yml
Normal file
59
mikrotikbackup_clean.yml
Normal file
@@ -0,0 +1,59 @@
|
||||
- name: Backup MikroTik config (text export only)
|
||||
hosts: mikrotik_routers
|
||||
gather_facts: no
|
||||
|
||||
vars:
|
||||
backup_dir: output
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user