Virtual servers are a huge boon to software development. Having rapidly deployed and recycled server instances can not only speed up development, but reduce the workload and bottleneck of DevOps procedures. With a pre-made development server blueprint, developers can quickly launch configured sandboxes and development machines complete with libraries, development environments, and database servers.

However, private and enterprise deployment may have requirements that virtual servers just don't meet. For instance, private deployment might have strict network security rules or bandwidth and connectivity requirements that can't be met by cloud-hosted virtual servers. In this case, it is necessary to have methods to not only quickly launch and configure cloud-hosted virtual servers for developers, but also for robust long-lasting instances for enterprise production.

In this tutorial, you will learn how to build a hybrid cloud software deployment solution, beginning with a rapid deployment development system using virtual cloud servers. We will then explore options available for deploying systems in staging and production environments on a private data center.

Tools Used

CenturyLink Cloud Compute servers are high-performance cloud servers. These enterprise-grade virtual machines are easy to deploy and manage from the CenturyLink Cloud Control Portal and via our powerful API.

Ansible is a tool for configuring and managing clouds and servers. It handles software deployment, cloud resource provisioning, task execution, and configuration management.

Before We Start

If you don’t have a CenturyLink Cloud account yet, head over to our website and activate an account. You’ll need it to access CenturyLink Cloud Compute servers. And, because automatically deploying and configuring virtual servers can be a complicated topic, you might want to check out our comprehensive collection of Knowledge Base articles on virtual servers.

Install Ansible on your machine. Most Linux distributions have available Ansible packages. For example, on Ubuntu or Debian you would use the following command:

sudo apt-get install ansible

For other distributions and operating systems, follow the installation instructions from the Ansible documentation.

Install CenturyLink Cloud SDK Python Modules

To use the Ansible module for provisioning and controlling CenturyLink Cloud products, you will need to install the Python SDK. Run the following command.

sudo pip install clc-sdk

Quickly Deploying Development Environments

Development environments differ from project to project. Sometimes they consist of just one server with relevant services, an IDE, and development tools installed. However, more complex projects that need to mirror production environments accurately can get very large. Some might need eight or more individual servers to provide a complete environment.

Deploying a development environment for each developer can be time consuming and expensive. Virtual servers have a lower overhead, both in terms of cost and manpower, and thus make a lot of sense for this sort of development environment. Automatically deployed and configured virtual servers make even more sense. In this tutorial, we will use Ansible to automate deployment of virtual private servers.

Creating Virtual Server Templates

Before setting up Ansible to provision and deploy a development environment, you will need to spend some time setting up and configuring one or more virtual servers as a template development environment. This process varies widely depending on your environment and requirements. Explore our other tutorials for information on deploying popular IDEs and database servers on CenturyLink Cloud Compute. For instance, check out our tutorial on deploying Eclipse Che in the cloud.

Once you have a fully configured development environment to convert to templates, follow the instructions below for each virtual server in the environment:

  1. Log into the CenturyLink Cloud Control Portal.
  2. From the Navigation menu, click Infrastructure > Servers. wl-hybrid-cloud-on-premise-1.png
  3. Navigate to the server you wish to convert to a template.
  4. Click convert to template. wl-hybrid-cloud-on-premise-2.png
  5. Enter the server's root password in the "source server admin or root password" box.
  6. Enter a description of the template in the "description" box.
  7. Click convert server to template. wl-hybrid-cloud-on-premise-3.png
  8. The server name doubles as the template name. Record it for later use.

Note: You can see a list of all server templates in the Templates server group.

Using Ansible to Automatically Provision Servers

To create an Ansible playbook for automatically provisioning and deploying CenturyLink Cloud Compute servers, follow these instructions:

  1. With a text editor, create a file called deploy_development_servers.yml and edit the file to look like the following example.

    • Pay close attention to the tasks. You have to create a clc_server task for each virtual server you are deploying.
    • The template items need to match the server template names that you recorded when creating templates.
    • Check the clc_server module documentation for more options.
    - name: Provision a Development Environment
      hosts: localhost
      gather_facts: False
      connection: local
        - name: Deploy IDE server
            name: ide
            template: <IDE-SERVER-TEMPLATE>
            count: 1
            cpu: 1
            memory: 1
            group: Development
            state: present
            add_public_ip: true
              - 22
              - 80
        - name: Deploy MongoDB server
            name: mgo
            template: <DB-SERVER-TEMPLATE>
            count: 1
            cpu: 1
            memory: 1
            group: Development
            state: present
            add_public_ip: true
              - 22
              - 80
              - 27017
  2. Execute the playbook using the following command. Replace "your-ctl-username" with your CenturyLink Cloud username, and "your-ctl-password" with your CenturyLink Cloud password.

    $ CLC_V2_API_USERNAME='your-ctl-username' CLC_V2_API_PASSWD='your-ctl-password' ansible-playbook -vv deploy_development_servers.yml

Deploying From the Cloud to On-Premises

You can also use Ansible to move developed applications from the cloud to on-premises private servers. There are many different approaches, but all of them should include staging environment to test deployment procedures. This is where automatic provisioning techniques are useful. If there is an existing deployment plan that mimics the production environment, this can be automated to provision a staging environment.

Staging environments allow a team to practice deploying new versions of software as well as configuration changes, database schema and data updates, and package updates. A staging environment should match the production environment as closely as possible. This enables you to catch any obstacles or speed bumps and correct them before they cause an IT disaster.

There are three main areas to plan for when deploying to your staging and production environments: package management, server provisioning, and database changes.

Distributing and Packaging Software

Every operating system and programming language has at least one packaging system. For example, Linux has deb, RPM, and several others. PHP uses composer; Node.js uses npm; and Ruby uses gem. Each of these provides an interface that downloads and installs packages from a remote package repository. Using a private package repository gives you the benefit of full dependency management and fail safes during installation. Take advantage of these valuable features.

Software can also be distributed via version control systems. For example, Git's branches and tags can mark software as ready for deployment. Note that while this can be a convenient way to distribute changes, it has its risks. As the size of your DevOps or development team grows, the chances of somebody accidentally doing the wrong thing to a source code repository grows exponentially. Hopefully, you will catch these inevitable problems in your staging environment, but they will slow you down. Once your team is large enough, move to a private package repository and save yourself the pain.

Virtual Servers, Containers, and Ansible

Virtual private servers offer benefits even when they're running on bare metal in a private data center. The ability to quickly distribute, provision, and manage containers simplifies software deployment and upgrades. In addition, the isolated environments offered by virtual servers keep runaway software from damaging the entire deployment environment.

Ansible provides many options for provisioning private virtual servers in private data centers as well as in the cloud. It controls virtual machines using hundreds of different modules. Here are a few to get you started:

Deploying Database Changes On-Premises

Once again, Ansible comes to the rescue. Check-out its extensive list of database modules to find out about available capabilities.

Database change management is tricky, and there isn't a consensus on the best way to handle substantial differences during deployment. Tools like DBdeploy and PHPmig reduce the pain of database change management. They make a good starting point for a solution that works in your production environment.

Next Steps

This guide is just the beginning of developing a robust hybrid IT solution for software development and deployment. After you get new developers started in the cloud while deploying changes safely to production, it's time to explore other automation solutions offered by Ansible.

Be sure to look into the possibilities offered by Runner, the CenturyLink Cloud Ansible-as-a-Service offering. It provides powerful tools for IT automation and infrastructure management. Since it's offered as a cloud service, it's available anywhere.

Sign-up for our Developer-focused newsletter CODE. Designed hands-on by developers, for developers. Keep up to date on topics of interest: tutorials, tips and tricks, and community building events.

We’re a different kind of cloud provider – let us show you why.