How to provision servers more quickly?

What options does Linode provide in terms of their virtual machines or technologies supported on their VMs that would allow me to provision servers more quickly?

Currently, when I build a Debian server for my web application, I go through two stages by running two Ansible playbooks, one to provision the server and the other to load my required packages and configure the server. I'm looking for a way to speed up that first stage. My provisioning playbook is comprised of these general steps:

  1. Create a Linode server via the Linode API. I specify my hostname, desired linode plan, and OS distribution.

  2. Update my DNS "A" records for the new server.

  3. Do some basic configuration to create my account like what is described in the Linode document "Getting Started."

  4. Update my local /etc/hosts file with the server's IP address as assigned to the linode.

  5. Other miscellaneous project-specific tasks.

My playbook generally takes about ten minutes to run but I'd like to be able to provision a server from the command line in under a minute. I envision a command something like this:

provision-server <hostname> <linode plan>

Ideally, I'd like to have some pre-built container that only requires these three inputs that can be spun up quite quickly. This container would also be pre-configured per step three with my account, my SSH keys, a minimal firewall, the hostname set, etc. I just want to specify my desired domain name and plan. Does Linode provide such a capability? Should I be looking at something like Docker? Also, I'd prefer not to have to pay for a server to be sitting idle to act as a template because I'd need one for each size plan. What are my options?

Thanks!

3 Replies

@robertf Great questions!

I'd prefer not to have to pay for a server to be sitting idle to act as a template because I'd need one for each size plan. What are my options?

You can use Linode Images to redeploy a preconfigured disk to new Linodes.
Images are created from a specific disk on a specific Linode and can then be deployed to any new or rebuilt Linodes in any region.

Keep an eye on https://github.com/displague/packer-builder-linode as it will move to the https://github.com/linode/packer-builder-linode real soon. Packer is a tool for making images.

You can also take advantage of StackScripts. You define the StackScript (any shebang script) and any variables that it should take when deployed.

Deploy your Linodes using that StackScript and supply any variables that you defined. This is similar in concept to UserData support, which I have a StackScript for :).

The StackScript could easily update your /etc/hosts file given a StackScript hostname variable provided at Linode disk creation time (avoid using the variable name hostname since that already has meaning in UNIX environments).

Here's another example of a StackScript I created. This one is for creating your Github username as a sudo enabled user account on your Linode with your Github SSH Keys authorized for SSH access. The GH_USERNAME is defined on line 2 and then referenced on line 48.

StackScript 10079: Rootless and GitHub User has sudo

Should I be looking at something like Docker?

If you are interested in running Docker Swarm, we have guides on how to run Docker Swarm on existing Linodes and guides for setting up Docker Swarm using the Docker Machine Driver.

You may be more interested to try out Kubernetes especially Rancher v2.2.0.

DC/OS and Nomad would be other options but there are no great Linode specific guides or installers for those choices at the moment (Work-In-Progress DC/OS Installer).

I just want to specify my desired domain name and plan. Does Linode provide such a capability?

The Linode CLI is very handy for quick and custom deployments. The --text, --format, and --no-headers options make it very easy to tie into shell scripts.

pip install --upgrade linode-cli
linode-cli linodes create --type=g6-nanode-1 --region=us-east --image=linode/debian9 --root_pass=$PASS
# you would need --stackscript and --stackscript-data to set the hostname

There is an official Linode Terraform provider and there are a number of Terraform Guides for Linode that can walk you through using that.

I have a fairly full featured example of how to put all the Linode resources together in Terraform but I'll try to pseudo-code it here:

provider "linode" {}

resource "linode_stackscript" {
  ... you can define a script here and inline it or source it
  ... from a script in the same directory
}

resource "linode_instance" "foo" {
  ... set the region and image, even a private image
  ... specify a stackscript id and stackscript data
  ... or just use
  provision "remote-exec" {
    inline = [
      "hostnamectl ..."
    ]
  }
}

resource "linode_domain" "domain" {
 ... define the domain, you may want to 'terraform import' this if it already exists on your account, or use a 'data resource'
}

resource "linode_domain_record" "record" {
 ... define a name, and set the target address from the Linode 
}

See https://github.com/terraform-providers/terraform-provider-linode/blob/master/examples/main.tf for more ideas from the example.

Ansible is obviously an option, and the new Linode_v4 Ansible module will let you setup a Playbook, like this Linode playbook that configures a Minecraft server.

Thanks very much for your thoughtful reply. For some reason, I'm not getting notifications when my questions are answered so I didn't know you had answered it.

I normally have so many events I just clear them out without looking, but I did see an event for your reply.

A few updates since I made the original reply:

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct