Getting Started With Ansible: Installing the Control Node

ansible automation Sep 13, 2023

Introduction:

In continuing the "Getting Started With Ansible" series, I will cover the control node, how to install it, and end with a quick demo of the process.  In the next post, we'll cover how to set up an inventory and connect to both a Linux (RHEL) and Windows host.  Before we start, though, I'd like to mention Ansible Automates.  Ansible Automates is a full-day conference I attended a few years ago and found very insightful.  It's presented throughout several cities in the US and other countries.  The schedule and locations are available at Ansible Automates: Global Tour (redhat.com).

If you're completely new to Ansible but are tasked with managing multiple servers, this series is for you.  

What is an Ansible Control Node?

At its core, the Ansible control node is the center of Ansible automation.  It's the control hub from which you orchestrate and manage your automation tasks.  Think of it as an orchestra conductor, guiding each instrument (in this case, your managed nodes) to produce a symphony of automation.  Here's a breakdown of its primary roles:

  • Centralized Management:  The control node serves as a centralized point for creating, organizing, and executing automation playbooks, which are sets of instructions for configuring and managing your infrastructure.
  • Inventory Management:  It maintains an inventory of all your managed nodes (the servers, devices, or systems you want to automate).  Ansible uses this inventory as a directory to locate and communicate with these nodes.
  • Task Execution:  The control node communicates with managed nodes via SSH, WinRM (Windows), or other connection methods to execute tasks defined in Ansible playbooks.  It collects information, applies configurations, and ensures your desired states are achieved across your infrastructure.
  • Report and Logging:  It provides reporting and logging capabilities, allowing you to monitor the execution of automation tasks, troubleshoot issues, and maintain a record of changes made to your systems.  

In the next sections, we'll explore the prerequisites for setting up a control node and the steps to get you started.

Requirements for Setting up an Ansible Control Node:

Ensuring that your system meets the requirements for setting an Ansible control node is essential.  Here are the basic prerequisites you should consider (check the documentation for the latest information -Installing Ansible — Ansible Documentation).

  • Hardware Requirements:  These are not currently provided in the official Installing Ansible documentation.  However, Ansible itself is not particularly resource-intensive.  The amount of CPU and RAM you need depends on the scale and complexity of your automation tasks.  A modern multi-core CPU and at least 4 GBs of RAM are typically sufficient for smaller setups.  
  • Cost:  Cost? We thought this was free.  Just kidding 😬, it is free unless you're using the Ansible Automation Platform (we'll cover this in another post).  Ansible is licensed under the GNU General Public Release version 3 (License).
  • Supported Operating Systems:  
    • Linux Distributions:  Ansible control nodes are primarily deployed on Linux systems.  Ansible supports a wide range of Linux distributions, including but not limited to:
      • Ubuntu
      • CentOS
      • Red Hat Enterprise Linux (RHEL)
      • Debian
      • Fedora
      • SUSE Linux Enterprise Server (SLES)
    • macOS:  Ansible can also be installed on macOS.
    • Windows:  While Ansible can control Windows hosts, the Ansible control node itself is not officially supported on Windows.  However, it can be used in a Linux virtual machine or Windows Subsystem for Linux (WSL).  In 2016, Microsoft released WSL 1, and in 2020 released WSL 2.  It is a compatibility layer that allows Linux binaries to run natively on Windows 10, Windows 11, and Windows Server editions 2019 or later.  I remember hearing the old idiom, "This is the Best Thing Since Sliced Bread, " growing up.  WSL 2 is pretty close.  Originally introduced to allow developers to work with most command-line tools, utilities, and applications directly in Windows without the overhead of a traditional virtual machine or dual boot setup.  However, as an admin, you can also take advantage of it.
  • Python:  Ansible is built on Python, so your control node must have Python installed.  Most Linux distributions come with Python pre-installed.  Ensure you have Python 3.9 or newer installed.  
  • Network Access:  Your Ansible control node must have network connectivity to the managed nodes (the servers or devices you intend to automate).  Typically, Ansible uses SSH to communicate with managed nodes.  WinRM is used to communicate with Windows nodes.  Windows SSH is experimental, but if you'd like to know more, check out Setting up a Windows Host — Ansible Documentation.  Be sure the Ansible control node can communicate using these protocols. 
  • Administrative Privileges:  You need administrative or root privileges on the control node to install Ansible and perform various administrative tasks.  Make sure you have the necessary permissions.
  • Internet Access (optional):  If you plan to use Ansible Galaxy to download roles and collections or if you need to install packages or dependencies during playbook execution, internet access from the control node will be required.

Installing Ansible on the Control Node:

Disclaimer:

I'd recommend completing the following steps in a lab environment.  Break things, fix them, and then repeat the process until you are comfortable using Ansible in a production environment.  Most production environments require security hardening.  We're not covering those in this series.  Ansible simplifies an admin's life, but if you don't get it right, it's much easier to impact 10s or 100s of machines with the press of enter vs. doing things the old way (manually).  You just can't beat having an environment that can be easily discarded and recreated to facilitate learning about new technologies. 

With the disclaimer out of the way, let's get started.

I'm using WSL 2 (Ubuntu) as my Ansible control node on an evaluation edition of Windows Server 2022.  Let's walk through the following steps:

  1. Ensure the latest updates have been applied to Windows Server 2022.
  2.  Open a command prompt as an administrator.
  3. Type "wsl --install" and press enter.  After a few minutes, you should see the message stating Windows Subsystem for Linux has been installed.  Go ahead and reboot.
  4. After the reboot, WSL will download and install Ubuntu by default.  You can change this behavior by providing the -d flag to wsl --install and specifying the distribution name.  See here for more information.
  5. Create your username and password.
  6. Update Ubuntu by running "sudo apt update && sudo apt upgrade".
  7. Next, we need to run commands to install Ansible, pip (Python package manager), and ansible-lint ( a command-line tool that helps you identify and avoid errors in your Ansible playbooks, roles, and collections).  Following these steps will ensure you install the latest version of Ansible and ansible-lint.
    1. sudo apt install software-properties-common
    2. sudo add-apt-repository --yes --update ppa:ansible/ansible
    3. sudo apt install ansible --yes
    4. sudo apt install python3-pip --yes
    5. export PATH=$PATH:~/.local/bin --- (This will add Ansible to your path).
    6. ansible --version --- (Verify the ansible version).
    7. python3 -m pip install ansible-lint
    8. ansible-lint --version --- (Verify ansible-lint version)

 

Congratulations!  You've just built an Ansible Control Node.  I highly recommend installing Visual Studio Code at this point.  I use it, along with the Ansible and WSL extensions, to build and manage the inventory file, playbooks, roles etc.  Download it from here.  Once installed, you should be prompted to install the WSL extension.

Next, connect to WSL from within VS Code and then open the extensions menu, from the left sidebar, and search for the Ansible extension.  This extension includes Lightspeed, a generative AI service that helps developers, or sysadmins, create Ansible content more efficiently.  You'll need either a Red Hat account (learn how to set one up here) or a GitHub account to enable Lightspeed.  I'll show this setup in the demo.

 

Demo:

Conclusion

Congratulations! You've taken your first steps into the exciting world of Ansible automation by setting up your very own Ansible control node. In this guide, we've explored the fundamental concepts of Ansible, from understanding the pivotal role of the control node to ensuring your system meets the necessary requirements. We've also covered the essential steps for configuring your control node.  But this is just the beginning. Ansible's power lies in its versatility and scalability.

So, what's next? Stay tuned for our upcoming blog posts and tutorials, where we'll dive into practical examples, use cases, and advanced techniques for harnessing Ansible's full potential. Whether you're a seasoned sysadmin looking to simplify your workflow or a newcomer eager to embrace automation, Ansible has something to offer.  How do you plan on using Ansible?  What other automation tools or scripting languages have you used? 

We'd love to hear from you!

Thanks for stopping by!

 

Whenever you're ready, there is one way I can help you gain hands-on experience: 

Automated Sandbox Fundamentals: I teach how to build a virtual lab using automation in this course. Learn how to create golden images, using both Windows and Linux, to easily spin up and add additional machines to your sandbox.  It's packed with 8 modules and the scripts you'll need to build your environment.  Start small, and scale as needed by easily changing the configuration file included with the course.

Give Me the Details