Resources UpCloud Ansible Collection

UpCloud Ansible Collection

UpCloud Ansible collection

Ansible is a popular configuration management tool for provisioning anything from individual cloud servers to entire cloud infrastructures. It executes the requested operation by following user-defined playbooks, lists of customisable actions written in YAML, on specified cloud servers.

Using Ansible, you can automate all bootstrapping operations, like installing and updating software, creating and removing users, and configuring system services. And to expand on those features, the UpCloud Ansible Collection adds a whole lot of new available configuration! options

UpCloud Ansible Collection

The collection of Ansible options for UpCloud integrates our services with the management tool. It really makes Ansible a great addition to your development resources. It extends the available configuration options on Ansible, giving you greater control of your new deployments. Simply by installing the module, you can use the additional inventory definitions in your Ansible playbooks.

Playbooks in Ansible are basic text language configuration files designed to be human-readable. At a basic level, playbooks can be used to manage the configuration and deployment of any remote machines. Furthermore, at an advanced level, playbooks can sequence multi-tier rollouts, delegate actions to entire clusters, integrate with monitoring services and load balancers.

Below is an example of the available inventory definitions.

plugin: community.upcloud.upcloud
zones:
  - fi-hel2
tags:
  - app
  - db
states:
  - started
network: 035a0a8a-7704-4da5-820d-129fc8232714

The inventory file allows you to easily manage multiple Cloud Servers and provisioning each according to your needs. You can filter servers based on their zone, tags, state, or the network they belong to.

Ansible and Terraform

Ansible is a great tool for making the configurations on your Cloud Servers once deployed. However, you first need to get the servers up and running. For this purpose, look no further than Terraform.

Terraform is a popular open-source infrastructure-as-code software tool that allows you to define infrastructure as code. It uses simple, human-readable language to safely and predictably manage cloud infrastructure by codifying APIs into declarative configuration files. Once the infrastructure has been deployed, Terraform is able to call on Ansible to do its thing to bootstrap the new Cloud Servers as required.

Running Ansible together with Terraform enables you to provision Cloud Servers directly after deployment. It allows you to make resources usable predictably, repeatably and much faster than configuring anything manually. It also enables easier maintenance and troubleshooting, thanks to the identical deployment steps which can eliminate human error.

Underneath is an example of how to integrate Ansible with your Terraform deployments.

# SSH connection and authentication
connection {
  host        = self.network_interface[0].ip_address
  type        = "ssh"
  user        = "root"
  private_key = file("/path/to/ssh-private-key")
}

# Wait until the Cloud Server is availble
provisioner "remote-exec" {
  inline = ["echo 'Cloud Server ready!'"]
}

# Provision the Cloud Server using Ansible
provisioner "local-exec" {
  command = <<-EOT
     ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook \
     -u root \
     -i '${self.network_interface[0].ip_address},' \
     --private-key '/path/to/ssh-private-key' \
     your-playbook.yml
  EOT
}

The above example includes three sections:

  1. Connection details use the public IP address of the Cloud Server, username, and the private SSH key counterpart of a public key the Cloud Server was deployed with to authenticate the connection.
  2. Remote execution provisioner is used to wait until the Cloud Server is reachable over SSH.
  3. Local execution provisioner then calls Ansible to run the requested playbook.

Get started

Ansible is quick to install and easy to run so head over to our Ansible collection GitHub repository to get started!

You might also be interested in learning more about Terraform. Check out our beginners tutorial and start codifying your cloud infrastructure.

Leave a Reply

Your email address will not be published. Required fields are marked *

Locations

Helsinki (HQ)

In the capital city of Finland, you will find our headquarters, and our first data centre. This is where we handle most of our development and innovation.

London

London was our second office to open, and a important step in introducing UpCloud to the world. Here our amazing staff can help you with both sales and support, in addition to host tons of interesting meetups.

Singapore

Singapore was our 3rd office to be opened, and enjoys one of most engaged and fastest growing user bases we have ever seen.

Seattle

Seattle is our 4th and latest office to be opened, and our way to reach out across the pond to our many users in the Americas.