Update mikrotikbackup.yml
This commit is contained in:
@@ -13,16 +13,15 @@
|
|||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Get router identity
|
- name: Get router identity
|
||||||
ansible.builtin.shell: >
|
shell: timeout 15 ssh -o StrictHostKeyChecking=no {{ ansible_user }}@{{ ansible_host }} -p {{ ansible_port }} "/system identity print"
|
||||||
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no
|
|
||||||
{{ ansible_user }}@{{ ansible_host }} -p {{ ansible_port }}
|
|
||||||
"/system identity print"
|
|
||||||
register: system_identity
|
register: system_identity
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
failed_when: system_identity.rc != 0 and system_identity.rc != 124 # 124 = timeout
|
||||||
|
|
||||||
- name: Set router name
|
- name: Set router name
|
||||||
set_fact:
|
set_fact:
|
||||||
router_name: "{{ system_identity.stdout.split(': ')[1] | trim }}"
|
router_name: "{{ system_identity.stdout.split(': ')[1] | trim }}"
|
||||||
|
when: system_identity.rc == 0
|
||||||
|
|
||||||
- name: Generate current date
|
- name: Generate current date
|
||||||
ansible.builtin.shell: date +%Y-%m-%d
|
ansible.builtin.shell: date +%Y-%m-%d
|
||||||
@@ -34,37 +33,30 @@
|
|||||||
current_date: "{{ date_output.stdout }}"
|
current_date: "{{ date_output.stdout }}"
|
||||||
|
|
||||||
- name: Export router config
|
- name: Export router config
|
||||||
ansible.builtin.shell: >
|
shell: timeout 15 ssh -o StrictHostKeyChecking=no {{ ansible_user }}@{{ ansible_host }} -p {{ ansible_port }} "/export"
|
||||||
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no
|
|
||||||
{{ ansible_user }}@{{ ansible_host }} -p {{ ansible_port }}
|
|
||||||
"/export"
|
|
||||||
register: export_output
|
register: export_output
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
when: system_identity.rc == 0
|
||||||
|
failed_when: export_output.rc != 0 and export_output.rc != 124
|
||||||
|
|
||||||
- name: Save export to local file
|
- name: Save export to local file
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: "{{ export_output.stdout }}"
|
content: "{{ export_output.stdout }}"
|
||||||
dest: "output/{{ router_name }}-{{ current_date }}.config"
|
dest: "output/{{ router_name }}-{{ current_date }}.config"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
when: export_output.rc == 0
|
||||||
|
|
||||||
- name: Create binary backup on router
|
- name: Create binary backup on router
|
||||||
ansible.builtin.shell: >
|
shell: timeout 15 ssh -o StrictHostKeyChecking=no {{ ansible_user }}@{{ ansible_host }} -p {{ ansible_port }} "/system backup save name={{ router_name }}-{{ current_date }}-backup"
|
||||||
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no
|
|
||||||
{{ ansible_user }}@{{ ansible_host }} -p {{ ansible_port }}
|
|
||||||
"/system backup save name={{ router_name }}-{{ current_date }}-backup"
|
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
when: system_identity.rc == 0
|
||||||
|
|
||||||
- name: Download binary backup
|
- name: Download binary backup
|
||||||
ansible.builtin.shell: >
|
shell: timeout 15 scp -o StrictHostKeyChecking=no -P {{ ansible_port }} {{ ansible_user }}@{{ ansible_host }}:{{ router_name }}-{{ current_date }}-backup.backup output/
|
||||||
scp -o ConnectTimeout=10 -o StrictHostKeyChecking=no
|
|
||||||
-P {{ ansible_port }}
|
|
||||||
{{ ansible_user }}@{{ ansible_host }}:{{ router_name }}-{{ current_date }}-backup.backup
|
|
||||||
output/
|
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
when: system_identity.rc == 0
|
||||||
|
|
||||||
- name: Remove backup file from router
|
- name: Remove backup file from router
|
||||||
ansible.builtin.shell: >
|
shell: timeout 15 ssh -o StrictHostKeyChecking=no {{ ansible_user }}@{{ ansible_host }} -p {{ ansible_port }} "/file remove {{ router_name }}-{{ current_date }}-backup.backup"
|
||||||
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no
|
|
||||||
{{ ansible_user }}@{{ ansible_host }} -p {{ ansible_port }}
|
|
||||||
"/file remove {{ router_name }}-{{ current_date }}-backup.backup"
|
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
when: system_identity.rc == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user