forked from jakub/ansible
Update mikrotikbackup_clean.yml
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
- name: Backup MikroTik config (text export only)
|
- name: Backup and/or Upgrade MikroTik
|
||||||
hosts: mikrotik_routers
|
hosts: mikrotik_routers
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
|
|
||||||
@@ -8,17 +8,7 @@
|
|||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
# Ensure local backup directory
|
# Always: identity + timestamp
|
||||||
# ----------------------------
|
|
||||||
- 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
|
- name: Get router identity
|
||||||
community.routeros.command:
|
community.routeros.command:
|
||||||
@@ -31,37 +21,43 @@
|
|||||||
router_name: "{{ identity_raw.stdout[0].split(': ')[1] | trim }}"
|
router_name: "{{ identity_raw.stdout[0].split(': ')[1] | trim }}"
|
||||||
tags: always
|
tags: always
|
||||||
|
|
||||||
# ----------------------------
|
|
||||||
# Timestamp
|
|
||||||
# ----------------------------
|
|
||||||
- name: Get timestamp
|
- name: Get timestamp
|
||||||
ansible.builtin.command: date +%Y-%m-%d_%H-%M-%S
|
ansible.builtin.command: date +%Y-%m-%d_%H-%M-%S
|
||||||
register: date_out
|
register: date_out
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
tags: always
|
||||||
|
|
||||||
- name: Set timestamp fact
|
- name: Set timestamp fact
|
||||||
set_fact:
|
set_fact:
|
||||||
ts: "{{ date_out.stdout }}"
|
ts: "{{ date_out.stdout }}"
|
||||||
|
tags: always
|
||||||
|
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
# Export config (stable for diff)
|
# Backup (tag: backup)
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
|
- name: Ensure local backup directory exists
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ backup_dir }}"
|
||||||
|
state: directory
|
||||||
|
mode: "0755"
|
||||||
|
delegate_to: localhost
|
||||||
|
tags: backup
|
||||||
|
|
||||||
- name: Export router config
|
- name: Export router config
|
||||||
community.routeros.command:
|
community.routeros.command:
|
||||||
commands: /export terse show-sensitive
|
commands: /export terse show-sensitive
|
||||||
register: export_cfg
|
register: export_cfg
|
||||||
|
tags: backup
|
||||||
|
|
||||||
# ----------------------------
|
|
||||||
# Save export locally
|
|
||||||
# ----------------------------
|
|
||||||
- name: Save export locally
|
- name: Save export locally
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: "{{ export_cfg.stdout[0] }}"
|
content: "{{ export_cfg.stdout[0] }}"
|
||||||
dest: "{{ backup_dir }}/{{ router_name }}-{{ ts }}.rsc"
|
dest: "{{ backup_dir }}/{{ router_name }}-{{ ts }}.rsc"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
tags: backup
|
||||||
|
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
# Upgrade router (tag: upgraded)
|
# Upgrade (tag: upgrade)
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
- name: Check current and latest available package versions
|
- name: Check current and latest available package versions
|
||||||
community.routeros.command:
|
community.routeros.command:
|
||||||
|
|||||||
Reference in New Issue
Block a user