Sandbox99 Chronicles

Getting Started with Ansible: Initial Setup Guide

ansible initial setup

Written by Jose Mendez

Hi, I’m Jose Mendez, the creator of sandbox99.cc. with a passion for technology and a hands-on approach to learning, I’ve spent more than fifteen years navigating the ever-evolving world of IT.

Published May 18, 2025 | Last updated on May 18, 2025 at 8:23AM

Reading Time: 4 minutes

Introduction

Ansible is an open-source IT automation tool developed by Michael DeHaan and later acquired by Red Hat in 2015. It is designed to simplify automation tasks such as configuration management, application deployment, and orchestration of complex workflows. What sets Ansible apart from many other tools is its agentless architecture and human-readable configuration using YAML.

Unlike Puppet or Chef, which often require a client-server model and agent installation, Ansible connects via SSH and uses simple modules to perform tasks. This makes it ideal for small-scale projects, beginners, and even enterprise-grade automation.

How It Works

Ansible operates on a control machine, which executes tasks on managed nodes (also known as target machines) over SSH. The target nodes must have Python installed (which most Unix-like systems already do). Ansible pushes instructions using modules and collects the output—no persistent connections or agents are required.

Here’s a simple diagram to visualize this:

  • Control Machine: Any Linux/macOS system with Ansible.
  • Managed Node: Any UNIX-like OS (Linux, BSD, etc.) accessible via SSH.

Sample folder structure from your Control Node machine:

Requirements

To use Ansible effectively, you’ll need a few basics in place. Here’s a summary:

RequirementDescription
SSH AccessPassword-based or preferably key-based SSH access to each target node
PythonMust be available on managed nodes (Python 2.7+ or Python 3+)
Supported OSMost Linux/BSD systems (Windows support exists but is more complex)
Control NodeAnsible must be installed on a Linux/macOS system (not supported on Windows)

Bonus Tips

  • Use SSH key pairs (ssh-keygen) to avoid typing passwords repeatedly.
  • Target nodes do not require Ansible or any additional software.

Main Use Cases

  1. Configuration Management: This is perhaps the most fundamental use case. Ansible can ensure that your servers and infrastructure components are configured consistently and correctly. You define the desired state of your systems in playbooks, and Ansible enforces that state, making it easy to manage large numbers of servers.
  2. Application Deployment: Ansible can automate the entire application deployment lifecycle, from pulling code from a repository to configuring application servers, databases, and load balancers. It ensures repeatable and reliable deployments, reducing manual errors and speeding up the release process.
  3. Orchestration: Ansible can coordinate complex workflows involving multiple systems. For example, you can use Ansible to deploy a multi-tier application where database servers, application servers, and web servers need to be configured and started in a specific order.
  4. Provisioning: While not a dedicated provisioning tool like Terraform or CloudFormation, Ansible can be used to provision resources on various cloud platforms (like AWS, Azure, Google Cloud) or virtualized environments. It can also be used to configure newly provisioned systems.
  5. Continuous Integration/Continuous Delivery (CI/CD): Ansible integrates well with CI/CD pipelines. It can be used to automate testing environments, deploy applications to staging or production, and manage the infrastructure required for the pipeline itself.
  6. Security Automation: Ansible can automate security tasks such as patching systems, enforcing security policies, configuring firewalls, and managing user access. This helps ensure that your infrastructure remains secure and compliant.
  7. Cloud Management: Ansible has extensive support for managing resources on major cloud providers. You can use it to manage instances, storage, networking, and other cloud services directly from your playbooks.
  8. Network Automation: Ansible can interact with network devices from various vendors to automate tasks like configuring switches, routers, and firewalls.
  9. Ad Hoc Task Execution: Sometimes you just need to run a single command or task across many servers quickly. Ansible’s ad hoc command execution allows you to do this without writing a full playbook.

In essence, if you have repetitive tasks to perform on multiple servers or systems, Ansible is likely a good tool to help you automate them, saving time, reducing errors, and improving consistency.

Setting Up the Demo Environment as initial

In this demo, we’ll set up Ansible on a control machine and connect to a remote target machine.

1. Install Ansible on the Control Node (If you have issues installing Ansible please goto this official site.)

For Debian/Ubuntu/MacOS:

# For production user or dedicated control machine in Linux
sudo apt update
sudo apt install ansible -y

# Or with pip (universal):
pip install ansible

# for MacOS
pipx install ansible

2. Prepare SSH Access to Target Nodes

Ensure SSH access is available:

ssh user@target-ip
# Setup key-based authentication (optional but recommended):
ssh-keygen -t rsa -b 4096
ssh-copy-id user@target-ip

3. Create an Inventory File

# inventory.ini
[target_nodes]
192.168.1.20 ansible_user=admin ansible_port=43322
192.168.1.21 ansible_user=admin ansible_port=22 #optional if default port
192.168.1.22 ansible_user=admin ansible_port=22 #optional if default port

4. Ping the Target Machine (Ad-hoc task)

Execute this command from your Control Node using the ping module to test your setup:

ansible -i inventory.ini target_nodes -m ping

Expected output:

192.168.1.20 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

Final Thoughts

Ansible is a versatile, agentless automation tool that simplifies complex IT operations across various environments. Whether you’re managing configurations, deploying applications, provisioning infrastructure, or automating security policies, Ansible offers a consistent and scalable approach through human-readable YAML playbooks.

With just a control machine, a few remote hosts, and SSH access, you can begin automating your infrastructure within minutes. Ansible is ideal for:

  • Pushing updates or patches to many servers
  • Installing and configuring services like Apache, Docker, or PostgreSQL
  • Enforcing consistent system states (Infrastructure as Code)
  • Scaling from a single server to hundreds or even thousands of machines

Its simplicity, readability, and efficiency make it a favorite among system administrators, developers, and DevOps engineers alike—suitable for both small setups and enterprise-grade automation. If it’s repetitive, error-prone, or system-related — Ansible can likely automate it.

Further Reading

This post focused on the initial setup and connection. In the next post, we’ll dive deeper into:

  • Writing your first Ansible Playbook
  • Understanding YAML syntax
  • Running real-world tasks like installing software and managing services

Stay tuned for future post Related to Ansible Playbooks.

Related Post

No Results Found

The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.

0 Comments

Submit a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.