Automating OS Setup Tasks or Use a Custom ISO

As you know almost all VPS providers give you the option to install OS with one click. I want to perform some tasks after OS has been installed such as:

  1. Setting root password
  2. Disabling root and adding new user
  3. Installing sudo, ufw, fail2ban etc.
  4. Install and configure nginx
  5. Install and configure mysql

Now I assume one way of doing it is to create a bash script that runs on start up and performs all the above functions. But the thing is not many VPS providers give the option to upload a startup script which means you have to manually run the script after VPS has been set up. Vultr is one provider (probably DO too) that gives you the option to run startup script while creating VPS so I was wondering if I can create a bash script that runs on start and do all these operations?

The second option is to create my own ISO with these preinstalled software and settings and use that ISO to install OS on VPS. My question is how can I create my own ISO?

You could use a Bash script, but most providers support Cloud Init :stuck_out_tongue:

Cloud init seems like ready made Linux templates. Two issues:

  1. It doesn’t seem to support Debian which I am targeting
  2. How do I add softwares (ufw, nginx etc) in Cloud init so they become part of template?

It does support Debian.

Start up scripts/receipes.

Well, you can archive these pretty easy with a bash script that runs at the first boot, like what I did at NanoKVM.

VM gets cloned from a template, MAC + bridge gets set, DHCP allocates the VM a IP address.
Now the script can run, sets a new root password + some other stuff posts that to an API and you are set.

You can go and connect to the new VM.

Yeah, I just do that and manually rsync the script over once the VM is deployed. Run the script and then it’s good to go. I also typically use a nice script from @Munzy which preps and sets itself up with snmp so it can be quickly added to librenms (if that’s part of your monitoring).

Does it support NDMP too?

No, sorry. Just SNMP and LMNOP.

Well that’s still pretty awesome.

1 Like

I’ve been summoned! What is up!?

Also which script you using Mason?

I always use ansible for this (Ansible Documentation — Ansible Documentation)

3 Likes

This one here :slight_smile: - https://github.com/Munzy/recipes/blob/master/recipes/debian/snmpd-install.sh

Hahaha Awesome <3

I need to do a small rework on it for systemctl.

1 Like

Ansible is king here. Everyone else has covered it pretty well but make roles for each of your setups and away you go.

3 Likes

The idea is to create VPS using Vultr API (or any other provider which supports API) and then install softwares using bash so everything is automated.
Another way of doing it is to upload custom ISO using API and install OS containing everything. Now coming to first approach where we can use bash, will I need root password to perform these operations? Or I can simply write bash for e.g. “apt install nano” and set it as startup script and it will install nano!?

Coming to ISO (or template whatever it is called), how do I make one? Let’s say if I have Hyper V on Windows 10 and I create a new Debian 9 VM, install all required softwares etc. then how can I make ISO/template out of it?

You could also use something like saltstack, and if supported, salt cloud. Spins up and sets everything up to your needs, terraform is also something that should work pretty well.

Yeah, some people have told me salt is better designed than ansible. I haven’t tried it and stick with ansible because I’m used to it, but salt is probably worth looking into.