dvtirol/pynetinstall

No default config, branding, environment variables

Opened this issue · 5 comments

etfz commented

Hi,

I don't know exactly what netinstall is capable of normally, but would it be possible to skip applying the default configuration after installation? And also install my custom branding package? Would the latter simply be a matter of uploading the package at the same time as the firmware?

Would it be possible to perhaps use environment variables instead of pynetinstall.ini?

About the boot images; do you know whether these ever change, or can I keep using the same ones "forever"?

I don't know exactly what netinstall is capable of normally, but would it be possible to skip applying the default configuration after installation?

do you mean no config at all (i.e., "/export" is empty) or using the mikrotik default config instead of a custom one? the former can be done (although it seems ill-advised) by specifying an empty config.rsc. the latter can be done by not specifying a config at all.

And also install my custom branding package? Would the latter simply be a matter of uploading the package at the same time as the firmware?

looking at this screenshot, i think it should be possible to do this by extending Flasher.do_files() - i'd like to support this (if only i had the time).

in our setup, we upload a default-config.rsc that:

  1. uses /tool/fetch to download additional packages and the real (dynamcially generated) config.rsc
  2. installs a on-startup scheduler that imports the config and removes itself
  3. reboots the device (which installs the downloaded packages and triggers configuration)

Would it be possible to perhaps use environment variables instead of pynetinstall.ini?

i don't know what use case you have in mind, but assuming you are trying to dynamically change which files to upload, you're supposed to write your own plugin that selects a routeros package and (optionally) default config based on mac address or model number (see readme). you can of course also write a small plugin that reads filenames from the environment.

etfz commented

Configuration question answered as per the other issue.

I tried simply copying the code that uploads the firmware package, adjusting the paths, and it seemed to work.

If you don't mind, roughly how do you work with your dynamic configuration system?

Regarding environment variables, I'm not sure that I had anything specific in mind, other than it being easier to edit than the ini file when using RouterOS. I saw the other open ticket with an example of a multi architecture plugin, and I'm certainly going to have a look at that, but I am going to need to figure out the values for some other architectures. What's an easy way of debugging that?

our workflow is like this (a little simplified):

  1. we upload the firmware and a static stage0-config.rsc.
  2. this stage0-config.rsc then on first boot calls /tool/fetch http://provisioning.internal/config?serial=abcdefgh dst-path=real-config.rsc to download the actual config from a small api we wrote.
  3. then, stage0-config.rsc downloads packages (also with /tool/fetch) if needed and installs a /system/scheduler start-time=startup on-event=/import real-config.rsc; /sys/scheduler/remove 0 and reboots.
  4. on reboot, the packages are installed and afterwards the config is imported and the scheduler removed.

the real-config.rsc is generated on the fly from jinja2 templates, with data provided by our dcim (data center infrastructure management) platform.

regarding values for other platforms: when you boot the netinstall image, pynetinstall will print out a line like this:

Device found! mac=48:a9:8a:xx:xx:xx, model=RB5009UG+S+, arch=arm64

this should give you all the information you need. sadly, the model number listed here is often different than what /system/routerboard/print or /system/resource/print says, so you can't rely on that. for example, note the space in netinstall and no space in /sys/routerboard/print:

[INFO ] -> Device found! mac=xx:xx:xx:xx:xx:xx, model=RB LtAP-2HnD, arch=mmips

[xxx] > /sys router pr
        board-name: LtAP
             model: RBLtAP-2HnD

[xxx] > /sys resource pr
        architecture-name: mmips
               board-name: LtAP
                 platform: MikroTik
etfz commented

Hi again,

I've since written a deployment script of my own, and it works well, but I've realised that the provided script gets installed as default configuration, meaning it's basically impossible to reset the device to factory settings without using netinstall again. Do you have any solution in place for this, or do you just leave it like that?

One option that looked promising was forgoing the netinstall script, and instead packaging it into a branding package as default configuration, which is executed automatically upon installing the package. You may subsequently install the factory configuration as the default by installing a branding package without a default configuration script. However this script does not seem to run when the branding package is installed by netinstall. netinstall has these options that I would like to try, but I don't know whether pynetinstall supports them, nor how I would use them:

-r - When the reinstallation process is performed, the current configuration will be reset, and for devices that have it, the default configuration will be applied (optional).
-e - Performing the reinstallation process will reset the device to an empty configuration.

your observations are correct. in case we want to reset a device to factory defaults, we remove it from our dcim. because our pynetinstall plugin uses the dcim database to select which firmware and config to install to a device, if it can't find it, it uploads some random 7.x firmware with config=None. this re-installs the factory config and is equivalent to -r.

if i understand -e correctly, it can be done by setting config to a file containing just a newline, as we figured out in bug 4. i haven't done any packet traces to confirm that this is equivalent, though.