Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A Quiz
🔍 Introduction
Now that you understand what Ansible is and why it’s
essential, it’s time to get practical.
This chapter will walk you through:
By the end, you’ll be ready to start managing servers
automatically!
🛠️ Part 1: Installing
Ansible
🔹 Installing Ansible on
Ubuntu/Debian
bash
CopyEdit
sudo
apt update
sudo
apt install -y ansible
✅ Verifies installation:
bash
CopyEdit
ansible
--version
🔹 Installing Ansible on
CentOS/RHEL/Fedora
bash
CopyEdit
sudo
dnf install -y epel-release
sudo
dnf install -y ansible
Older CentOS/RHEL might need:
bash
CopyEdit
sudo
yum install ansible
🔹 Installing Ansible on
macOS (using Homebrew)
bash
CopyEdit
brew
install ansible
✅ Verify installation:
bash
CopyEdit
ansible
--version
🔹 Installing Ansible via
Python (Any OS)
Using pip:
bash
CopyEdit
pip
install ansible
Good for virtual environments and custom setups.
📋 Summary: Installation
Methods
OS/Platform |
Method |
Ubuntu/Debian |
APT package manager |
CentOS/RHEL/Fedora |
DNF or YUM +
EPEL Repository |
macOS |
Homebrew |
Any OS |
Python pip
installer |
🏗️ Part 2: Setting Up
the Ansible Control Node
The control node is where you:
Typical control nodes:
Ansible does not require any agents on managed nodes
— just SSH access!
🔹 Verifying SSH Access
Test if your control node can SSH into a managed node:
bash
CopyEdit
ssh
user@192.168.1.10
If successful, Ansible can communicate with that server.
🔹 Setting up SSH Key
Authentication (Recommended)
bash
CopyEdit
ssh-keygen
bash
CopyEdit
ssh-copy-id
user@192.168.1.10
Now, Ansible can connect without password prompts.
📚 Part 3: Creating Your
First Inventory
An inventory tells Ansible which hosts to
manage.
Inventories can be:
📋 Example: Static
Inventory File
inventory.ini
ini
CopyEdit
[webservers]
192.168.1.10
192.168.1.11
[dbservers]
192.168.1.20
✅ Group servers for targeted
playbooks.
📋 Directory Structure
Recommendation
bash
CopyEdit
project-name/
├── inventory.ini
├── playbooks/
│ └── setup-webserver.yml
└── ansible.cfg
Organized projects scale better!
📦 Part 4: Running Your
First Ansible Commands
Use ad-hoc commands to quickly test Ansible without
writing playbooks yet.
🔹 Ad-Hoc Command Examples
Ping all servers:
bash
CopyEdit
ansible
all -i inventory.ini -m ping
✅ You’ll get a success message
from reachable hosts.
Check uptime:
bash
CopyEdit
ansible
all -i inventory.ini -a "uptime"
✅ Runs shell commands remotely.
Install Apache on webservers:
bash
CopyEdit
ansible
webservers -i inventory.ini -b -m apt -a "name=apache2 state=present"
⚙️ Understanding the ansible.cfg
File
ansible.cfg controls Ansible’s default behavior.
Example basic configuration:
ini
CopyEdit
[defaults]
inventory
= ./inventory.ini
remote_user
= ubuntu
host_key_checking
= False
retry_files_enabled
= False
✅ Localizes settings to your
project folder.
📈 Tips for a Smooth First
Setup
Tip |
Reason |
Use SSH keys
instead of passwords |
Easier automation |
Group hosts logically |
Cleaner
playbooks |
Use an ansible.cfg
per project |
Easier maintenance |
Set host_key_checking = False in dev |
Avoid manual
SSH prompts |
Always test with
ansible all -m ping |
Confirm connections
before running tasks |
🔥 Common First-Time
Errors and Solutions
Error |
Cause |
Solution |
Permission denied
(publickey) |
SSH keys not copied |
Use ssh-copy-id |
Host unreachable |
Bad IP, no
route, firewall |
Double-check
IP and network |
Failed to connect
to host |
SSH server not running |
Start/restart sshd on
managed node |
Missing SUDO permissions |
become: true
missing in Playbook |
Add privilege
escalation |
🛤️ Hands-On: Quick
Starter Project
Congratulations — you're already managing infrastructure the
Ansible way!
🚀 Summary: What You
Learned in Chapter 2
Ansible setup is surprisingly simple — and it sets
you up for powerful automation workflows in the next chapters.
Answer:
Ansible is an open-source automation tool used for configuration management,
application deployment, and orchestration. It helps automate the process of
setting up and maintaining systems in a desired state without manual
intervention, using simple YAML-based playbooks over SSH connections.
Answer:
Unlike Puppet or Chef, Ansible is agentless (no software needed on
managed nodes), uses SSH for communication, and adopts a human-readable
YAML syntax instead of custom DSLs (domain-specific languages). This makes
it easier to install, learn, and operate, especially for small to mid-sized
teams.
Answer:
You only need to install Ansible on a control node (your local machine,
a management server, etc.). It then connects to managed nodes (servers,
devices) via SSH (Linux/macOS) or WinRM (Windows) to execute tasks. No software
needs to be installed on the managed nodes.
Answer:
A playbook is a YAML file that defines a set of tasks for Ansible to perform on
target hosts. Playbooks describe what the system should look like, not
how to achieve that state, making it easier to manage system configurations
declaratively.
Answer:
Idempotence in Ansible means that applying the same playbook multiple times
produces the same result — no unintended changes. Modules are designed
to detect the current system state and only perform actions if changes are
needed.
Answer:
Ansible Inventory is a file (typically hosts.ini or dynamic inventory scripts)
listing all the machines you want to manage. It organizes hosts into groups
(like [webservers], [dbservers]) and defines connection details for efficient
targeting and task execution.
Answer:
Yes. Ansible has built-in modules for managing cloud resources across AWS,
Azure, GCP, OpenStack, and more. You can provision VMs, configure networks,
manage storage, and deploy apps using the same Ansible playbooks.
Answer:
Ansible Vault is a feature that allows you to encrypt sensitive data
(like passwords, API keys) within your Ansible files. This ensures that secrets
remain protected even if your playbooks are stored in public or shared
repositories.
Answer:
Ansible can scale from managing a few servers to thousands by using
features like dynamic inventory, parallel task execution, and tools like Ansible
AWX/Tower for centralized control, scheduling, and reporting across large
environments.
Answer:
No. While Ansible is best known for managing Linux and Unix systems, it also
supports Windows systems through WinRM connections and provides specific
modules for Windows tasks like configuring IIS, managing services, and
installing applications.
Please log in to access this content. You will be redirected to the login page shortly.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Comments(0)