Community discussions

 
User avatar
omega-00
Forum Guru
Forum Guru
Topic Author
Posts: 1166
Joined: Sat Jun 06, 2009 4:54 am
Location: Australia
Contact:

Flashfig vs netinstall and scripting provisioning functions

Tue Nov 24, 2015 4:25 am

I've been looking at ways to automate/simplify the deployment of batches of MikroTik devices using some of the provided utilities. After some testing and research on the subject of Flashfig vs Netinstall; it seems that both have limitations.

Flashfig:
1. Only works on first boot of the device (repeatable by change to routerboard boot settings) by default
2. Doesn't commit the config change to default (if the device is reset it will return to the mikrotik default-config)
3. Powers down the device when configuration has been added (so it's clear which ones are done)
4. Takes about 5 seconds to complete per device

Netinstall:
1. Must be manually activated for each device via the program
2. Commits applied config as the default (even if the device is reset)
3. Device will restart after config is applied
4. Takes about 1 minute to complete per device

What I'd really like is to be able to automate is the following:
a) apply a replacement default config to the device (via netinstall)
b) apply a config to the device via an automated method (netinstall/flashfig/etc) to be boxed up and sent out.

And better still be able to do all of these with as little human input as possible.

I'm curious to hear what others are doing but I'll keep you updated on any brainwaves I have here :-)
brightwifi.com | mikrotik-routeros.com | MTCNA,MTCWE.MTCTCE | Give karma where due
 
User avatar
omega-00
Forum Guru
Forum Guru
Topic Author
Posts: 1166
Joined: Sat Jun 06, 2009 4:54 am
Location: Australia
Contact:

Re: Flashfig vs netinstall and scripting provisioning functions

Tue Nov 24, 2015 5:24 am

Another problem with using netinstall vs flashfig is the amount of time it takes to reinstall a device via netinstall; vs flashfig which can accept and apply configs to multiple devices in the space of a minute. I haven't tested if it can apply configs to more than one device connected at a time but I know netinstall cannot do this and you can't run multiple instances of the netinstall application.
brightwifi.com | mikrotik-routeros.com | MTCNA,MTCWE.MTCTCE | Give karma where due
 
dprovencher
just joined
Posts: 16
Joined: Sat Feb 23, 2013 3:35 am

Re: Flashfig vs netinstall and scripting provisioning functions

Wed Nov 16, 2016 6:37 am

I'm looking to do the exact same thing. Can you share if and how you did it?

Thank you,
 
Dude2048
Frequent Visitor
Frequent Visitor
Posts: 51
Joined: Thu Sep 01, 2016 4:04 pm

Re: Flashfig vs netinstall and scripting provisioning functions

Wed Dec 28, 2016 3:04 pm

The DHCP server has a predictable way of giving out the ip's. So, I thought, why not use that feature.

I made a csv in Excel an named it AP.txt. It contains an IP adres with a name. Don't forget to give a enter after the last line in notepad!!!

AP.txt
AP57,192.17.16.221
AP58,192.17.16.222
AP59,192.17.16.223
AP60,192.17.16.224
AP61,192.17.16.225
AP62,192.17.16.226
AP63,192.17.16.227
And so on...

Don't forget about the max file size of 4K.

I made sure that I could read the file, so I copied it to a RB2011 and executed this scrip from the terminal.
:global content [/file get AP.txt contents ];
:global contentLen [:len $content ];

:global lineEnd 0;
:global line "";
:global lastEnd 0;

do {
:set lineEnd [:find $content "\r\n" $lastEnd ];
:set line [:pick $content $lastEnd $lineEnd];
:set lastEnd ( $lineEnd + 2 );
:global tmpArray [:toarray $line];
:if ( [:pick $tmpArray 0]!= "" ) do={
:put [:pick $tmpArray 0];
:put [:pick $tmpArray 1];}

} while ($lastEnd < $contentLen)
I left in the globals to see how the script executed. You can see the output in /system/script/environment.

Since that was working I can pick out a name (APxx) thanks to the ip address. The script below is already kind of production ready so it won't give an output.

 :global content [/file get AP.txt contents ];
                :global contentLen [:len $content ];
                :global lineEnd 0;
                :global line "";
                :global lastEnd 0;
                :global apname [:pick [/ip address get 0 address] 0 [:find [/ip address get 0 address ] "/"]];

                do {
                     :set lineEnd [:find $content "\r\n" $lastEnd ];
                     :set line [:pick $content $lastEnd $lineEnd];
                     :set lastEnd ( $lineEnd + 2 );
                     :global tmpArray [:toarray $line];
                     :if ( [:pick $tmpArray 0]!= "" ) do={
                          :if ("$apname"= [:pick $tmpArray 1]) do={
                                /system identity set name=[:pick $tmpArray 0];
                                /ip dhcp-client remove 0;
                                /ip address add address=[:pick $tmpArray 1] netmask=255.255.254.0 interface=BridgeVlan99
                                }
                           }
                        } while ($lastEnd < $contentLen)
Ok, here goes.
What I want is:
-CPE must be upgraded to whatever version
-Unneeded packages should be disabled
-Set IP and hostname.

What I did
-Set up dhcp server with exact range of CPE's to roll out
-Made a script for flashfig with a basic config and the following script in it.
-flashfigged the CPE's and kicked of this script with netwatch. Just to make sure that there is an IP connection.

 :local DHCPDisabled [/system package get dhcp disabled];
:local MyVersion [/system resource get version];
:local WantedVersion "6.36.4 (bugfix)";

if ($DHCPDisabled=false) do={
                :if ($MyVersion=$WantedVersion) do={
                /system package enable [/system package find name="system"]
                /system package disable [/system package find name="ipv6"]
                /system package enable [/system package find name="wireless"]
                /system package disable [/system package find name="hotspot"]
                /system package disable [/system package find name="dhcp"]
                /system package disable [/system package find name="mpls"]
                /system package disable [/system package find name="routing"]
                /system package disable [/system package find name="ppp"]
                /system package enable [/system package find name="security"]
                /system package enable [/system package find name="advanced-tools"]
                /tool fetch address=192.17.16.190 src-path=AP.txt mode=ftp user=FTP password=FTP
                :delay 10

                :global content [/file get AP.txt contents ];
                :global contentLen [:len $content ];
                :global lineEnd 0;
                :global line "";
                :global lastEnd 0;
                :global apname [:pick [/ip address get 0 address] 0 [:find [/ip address get 0 address ] "/"]];

                do {
                     :set lineEnd [:find $content "\r\n" $lastEnd ];
                     :set line [:pick $content $lastEnd $lineEnd];
                     :set lastEnd ( $lineEnd + 2 );
                     :global tmpArray [:toarray $line];
                     :if ( [:pick $tmpArray 0]!= "" ) do={
                          :if ("$apname"= [:pick $tmpArray 1]) do={
                                /system identity set name=[:pick $tmpArray 0];
                                /ip dhcp-client remove 0;
                                /ip address add address=[:pick $tmpArray 1] netmask=255.255.254.0 interface=BridgeVlan99
                                }
                           }
                        } while ($lastEnd < $contentLen)
                :foreach i in=[/system script find] do={ :if ([:typeof [:find [/system script get $i name] "Step2"]]!="nil") do={/system script remove $i};}
                :if ([/tool netwatch find host="192.17.16.190"]!="") do={/tool netwatch remove [find host="192.17.16.190"]}
                /system reboot
                } else={
                /tool fetch address=192.17.16.190 src-path=routeros-mipsbe-6.36.4.npk mode=ftp user=FTP password=FTP
                :delay 10
                /system reboot
                }
}



What does it do;
-It checks (netwatch) if an ip is up and starts script
-Checks if the dhcp client is running
-Checks if the OS version is ok. If not.. FTP
-Reboot
-It checks (netwatch) if an ip is up
-Checks if the dhcp client is running
-Checks if the OS version is ok.
-Disable the packages that I don't need
-Gets a name via the script that reads AP.txt.
-Kills itself and the netwatcher.
-Reboots

Took me 1 hour to do 40 units.

Who is online

Users browsing this forum: No registered users and 9 guests