45 lines
1.8 KiB
YAML
45 lines
1.8 KiB
YAML
---
|
|
|
|
# Test mikrotik
|
|
|
|
- name: ADD SCRIPT ISP_name_check for RTO
|
|
hosts: MK_RT
|
|
|
|
tasks:
|
|
|
|
- name: Remove old script, add new script
|
|
routeros_command:
|
|
commands:
|
|
- /system script remove ISP_name_check
|
|
- >
|
|
/system script add dont-require-permissions=no name=ISP_name_check owner=admin policy=\
|
|
read,write,policy,test source="/system script run JParser;\r\
|
|
\n/tool fetch url=\"https://wtfismyip.com/json\" keep-result=yes; delay 1s;\
|
|
\r\
|
|
\n:local count 0;\r\
|
|
\n:local countBr 0;\r\
|
|
\nlocal 3g [ ip route find where dst-address=0.0.0.0/0 gateway=ppp-out1];\r\
|
|
\nlocal 4g [ ip route find where gateway ~\"192.168\" or gateway=lte1];\r\
|
|
\nlocal brIsp [ interface find where name=\"br_isp\"];\r\
|
|
\n:global JSONIn [/file get json contents];\r\
|
|
\n:global fJParse;\r\
|
|
\n:global JParseOut [\$fJParse];\r\
|
|
\n:local ISP (\$JParseOut->\"YourFuckingISP\");\r\
|
|
\nforeach br in=\$brIsp do={set countBr (\$countBr+1) };\r\
|
|
\nforeach x in=\$3g do={set \$count 777 };\r\
|
|
\nforeach z in=\$4g do={set count (\$count+1)};\r\
|
|
\nif ( \$countBr=0 ) do={/interface bridge add disabled=yes name=br_isp}\r\
|
|
\n\r\
|
|
\nif ( \$count=2) do={/interface set [ find name=br_isp ] comment= \"4G-\$IS\
|
|
P\"} else={/interface set [ find name=br_isp ] comment= \$ISP }\r\
|
|
\nif ( \$count=1) do={/interface set [ find name=br_isp ] comment= \"4G-Huaw\
|
|
ei_RT-\$ISP\"}\r\
|
|
\nif ( \$count=777) do={/interface set [ find name=br_isp ] comment= \"3G-\$\
|
|
ISP\"}"
|
|
|
|
register: version_output
|
|
|
|
- name: Display facts variables
|
|
debug:
|
|
var: version_output
|