AzureFunBytes – Ansible on Azure

Jay Gordon

There are so many tools to use to build your cloud infrastructure to choose from. Getting details on what options are available to you can help you determine the best path forward in your DevOps journey.

Ansible is an open-source automation tool that allows you to codify your process of Configuration Management and Continuous Delivery. Ansible provides a radically simple method of managing IT resources by utilizing an agentless deployment methodology.

Ansible is multi-platform giving you a number of options on what OS’s you can deploy to. With Ansible you can work with your Windows hosts and install packages via Chocolatey or use yum to deploy required packages on your Ubuntu server. You’ll find a level of management that’s flexible and that makes sense for beginners or advanced users of automation software.

Let’s take a look at what makes up, and how to use Ansible. You can review some of the pieces that come together and even do a video demo of using Ansible right in the Azure Cloud Shell.

Components that make up an Ansible deployment

Let’s define a few of the parts that make up an Ansible powered deployment.

Nodes are the computers we’re using to deploy with. Ansible has two main types of nodes we should concern ourselves with:

Control node: A control node is any machine with Ansible installed. You can invoke the command using the ansible or ansible-playbook binaries from any control node. These nodes are typically where you’re going to execute your commands and send them to the nodes you’d like to deploy to.

You can install the ansible binary on almost any UNIX-like platform such as Red Hat Linux, Debian, CentOS, OSX, BSD, and many more. At the time of this blog post, there is no control node software for Windows. You can manage and deploy to Windows servers, you will just have to use a UNIX-like system to act as your control node.

Currently, Ansible can be run from any machine with Python 2 (versions 2.6 or 2.7) or Python 3 (versions 3.5 and higher) installed. If you are using Microsoft Azure, you can utilize the Cloud Shell in your portal which already has the ansible binary installed and ready:

Image ansible

You can get even more details on how to get started by checking out the Configure Ansible using Azure Cloud Shell Quickstart document.

Managed Nodes: Managed nodes are exactly that, the nodes that your control node is managing. Managed nodes can be referred to as hosts and do not require you to install Ansible on them because Ansible is agentless. There is no need for you to install some form of bootstrap process to provide and configure a local agent on your managed nodes. Your control node will communicate over SSH to access and configure your managed nodes.

Inventory: It’s just what it sounds like, it’s the inventory of the nodes that are being managed with the Ansible control node. You can store a list of these nodes in a flat-file that’s stored in the filesystem at /etc/ansible/hosts. An example inventory file may resemble this:


[domain controllers]

We specify the main host in then provide its sub-components in our brackets. After our brackets that identify what each node is, we provide the fully qualified domain names that are mapped to the nodes that are currently controlled by Ansible. You can find even more details on how to build your inventory by visiting this document from the Ansible website.

Modules are reliable, repeatable standalone scripts the Ansible leverages to run the commands you make part of your deployment. Modules (also referred to as “task plugins” or “library plugins”) are code that you can use in the command line or add to a task list known as a playbook. You can utilize thousands of existing modules like the Azure ansible module that allows you to execute a number of Azure specific tasks on your nodes. You can control security with Key Vault, create databases with Cosmos DB, or even build your containers all thanks to this module.

You can also develop your own module! Ansible provides documentation and some boilerplate python code to help you start writing modules to create functionality that may not be in one of the thousands of existing modules.

Tasks are the things you do with Ansible on your nodes. So, if you were going to install nginx on an Ubuntu server, that would be considered a task.

Playbooks are ordered lists of the tasks you’d like to complete on your nodes. These playbooks are YAML files that declare your configuration and run the tasks to get your node in the desired state. You can choose to run your playbook commands synchronously or asynchronously which allows you a full fleet deployment or rolling updates.

Let’s give Ansible a spin now, take a look at this tutorial with all the basics of using Ansible on Azure to control a virtual machine.

Azure Implementation

Ansible isn’t just for virtual machines. Ansible can help you build and manage your Azure resources! You can configure a Web App for App Service to reduce your total overhead of your application infrastructure and deploy your code right from your repository.

You can start using Ansible on Azure with some help from some key docs from the Microsoft Docs website. Let’s review some of the docs that will get you on the way to building with Ansible.

Ansible on Azure Docs – Learn how to use Ansible to automate cloud provisioning, configuration management, and application deployments.

Quickstart: Configure Ansible using Azure CLI – This quickstart shows how to install Ansible using the Azure CLI.

Quickstart: Configure Linux virtual machines in Azure using Ansible – This article presents a sample Ansible playbook for configuring Linux virtual machines.

These docs and the video tutorial should provide you with all the basics for you to start using Ansible. With all the choices out there in the world to handle your deployment automation, it’s great to have one that’s ready for Azure today.


Byte-sized content with a live Twitch show!

Learn about Azure fundamentals with me!

Join me, ask questions, and learn about Azure!

Live stream is available on Twitch at 2 pm EST Thursday. You can also find the recordings here as well:

Useful Docs:

Microsoft Learn: Azure Fundamentals
Microsoft Azure: $200 Free Credit
Using Ansible with Azure
Quickstart: Configure Ansible using Azure Cloud Shell
Ansible (Red Hat)


Discussion is closed.

Feedback usabilla icon