Updated on 17.5.2022

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 newly 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, and integrate with monitoring services and load balancers.

Below is an example of the available inventory definitions.

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

The inventory file allows you to manage multiple Cloud Servers easily and provision 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' \

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. A remote execution provisioner is used to wait until the Cloud Server is reachable over SSH.
  3. The 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.

Hashicorp Packer logo

UpCloud Packer Builder

Packer is an easy-to-use automation solution for creating any type of machine images. It embraces modern configuration management by allowing automated software installation and setup within Packer-built images. UpCloud Packer builder integrates Packer with our Cloud Servers and makes creating private templates fast! Packer plugin UpCloud Packer builder is a plugin for Packer to simplify template […]

UpCloud Terraform Provider

Terraform is a popular open-source infrastructure-as-code software tool created by HashiCorp. It allows users to define infrastructure as code using a simple, human-readable language to safely and predictably manage cloud infrastructure by codifying APIs into declarative configuration files.

Back to top