Good evening, after several searches for a program to automatically update RouterOS and its firmware to a specific version I found Ansible, a tool that is working well for now.
I created this script and it is working but it would be much more convenient to be able to send commands to the routerboard after a certain number of seconds
using a delay in this way it should be possible to send the various commands to the Routerboard without having to use /system script and /system scheduler, could such a configuration be possible?
I was thinking of using the form
“ansible.builtin.wait_for module”
oppure “loop (until) e when”
What do you think?
#Sure work with RouterOS 6.48.6
---
- name: Auto-Upgrade-and-Update-Mikrotik-Script
hosts: mikrotik
tasks:
#Upload the .npk file (or any other file) of the operating system to the root "/" on Mikrotik (ip mikrotik:folder root)
- name: Execute SCP Secure Copy Protocol
ansible.builtin.shell: scp routeros-mipsbe-6.49.8.npk admin@192.168.88.1:/
- name: UPGRADE FIRMWARE with Mikrotik scripts and scheduler
community.network.routeros_command:
commands:
- /system scheduler add name=Start-Upgrade-and-reboot-script on-event=":delay 8s;\r\
\n/system scheduler disable Start-Upgrade-and-reboot-script \r\
\n/system script run upgrade-and-reboot\r\
\n" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-time=startup
- /system script add dont-require-permissions=no name=upgrade-and-reboot owner=admin policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=\
"/sys routerboard upgrade\r\
\n:delay 8s;\r\
\n/sys reboot\r\
\n"
#Simple Reboot
- name: Reboot
community.routeros.command:
commands:
- :execute {/sys reboot;}