I work on remote servers, and its a painfull process to go into Rescue Mode everytime I screw something up when it comes to network configuraitons.

Are there a way to implement something like:

Netplan apply /customscript.yaml 

That I can use when I troubleshoot network configurations. So the server gets its "defaults" if I do a cold reboot.

6

2 Answers

There is a new way to do this in Bionic: netplan try.

In your case, netplan try --config-file foo.yaml should do what you want.

The manpage isn't very helpful as it mostly describes the config file format, but --help gives you a pretty good outline of the tool:

ubuntu@netplan:~$ netplan try --help usage: /usr/sbin/netplan try [-h] [--debug] [--config-file CONFIG_FILE] [--timeout TIMEOUT] Try to apply a new netplan config to running system, with automatic rollback optional arguments: -h, --help show this help message and exit --debug Enable debug messages --config-file CONFIG_FILE Apply the config file in argument in addition to current configuration. --timeout TIMEOUT Maximum number of seconds to wait for the user's confirmation 

First I created a sh script, placed it in /etc/netplan/ and named it backup.sh

#!/bin/sh # -q quiet # -c nb of pings to perform ping -q -c5 aa.bb.cc.dd > /dev/null if [ $? -eq 0 ] then : #do absolutly nothing! server can ping its external IP. else # restore, working config to netplan. cp -f /etc/netplan/02-netcfg.yaml /etc/netplan/01-netcfg.yaml # apply network config. netplan apply fi 

This script revert the changes I have made, to a working configuration setup that I have stored in 02-netcfg.yaml If i cant ping the server IP. I have masked my server IP address whit aa.bb.cc.dd So you have to replace that whit the IP you want to ping, in order to execute the "else" in the if.

Then i set this script to run everytime the server restart, as well as enable a Cron job for it that runs every 3 minutes when i work on network configurations.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy