Overview
In this complete guide, you’ll learn how to install Ansible on Ubuntu, configure your own Ansible inventory file, connect to remote CentOS servers, and automate common tasks such as installing packages, managing services, and deploying a website using Ansible ad-hoc commands.
By the end of this tutorial, you’ll be able to manage multiple Linux servers efficiently with Ansible — the most powerful automation tool for DevOps and system administrators.
Table of Contents
What is Ansible?
Ansible is an open-source IT automation tool used for configuration management, application deployment, and task automation.
It uses simple YAML playbooks and SSH for remote communication — making it agentless, fast, and easy to use.
Key Benefits of Ansible:
No agents required on remote hosts
Human-readable YAML syntax
Works with Linux, Windows, and network devices
Ideal for DevOps automation and CI/CD pipelines
Prerequisites
Before you begin, make sure you have:
Ubuntu server (control node) with root or sudo access
Remote CentOS host (managed node) with SSH enabled
SSH key-based authentication between Ubuntu and CentOS
Internet connectivity to install Ansible packages
Install Ansible on Ubuntu
Run the following commands to install Ansible on Ubuntu:
Verify Ansible Installation
Once installed, verify the version and configuration using:
Example Output:
✅ Tip: The config file
/etc/ansible/ansible.cfgdefines defaults such as inventory paths, privilege escalation, and connection types.
Configure Custom Ansible Inventory
You can use a custom inventory file instead of the default /etc/ansible/hosts.
Create one under /root/hosts:
Sample Inventory:
🧩 Explanation
🟢 [centos]
This defines a host group named
centos.You can use this group name in your Ansible commands or playbooks (e.g.,
-l centosorhosts: centos).
🖥️ 192.168.1.17 and 192.168.1.18
These are the IP addresses of the managed hosts.
Each line defines one managed node (target system).
⚙️ Connection parameters
| Parameter | Description |
|---|---|
ansible_port=22 | SSH port used to connect (22 is the default SSH port). |
ansible_user=ansible | The Linux user Ansible will log in as on that host. |
ansible_ssh_private_key_file=/root/ansible | Path to the private SSH key used for authentication. This key must match the public key in the target host’s /home/ansible/.ssh/authorized_keys. |
Check Connectivity Using Ansible Ping Module
To verify that your control node can reach the managed host, run:
Output:
-i /root/hosts→ specifies the inventory file you created.-m ping→ uses Ansible’s ping module, which checks SSH connectivity and Python availability (not ICMP ping).
And if you would like to check the connectivity of only one host in the centos group:
ansible 192.168.56.161 -i /root/hosts -m ping
🔎 💡 Tip: If you’re not using an SSH key for authentication, you can enable password-based authentication by using the
-kand-Koptions — where-kprompts for the SSH user password and-Kprompts for the privilege escalation (become) password. For example: ansible 192.168.56.161 -i /root/hosts -m ping -k (For connectivity checking only ssh user password is required, no need for privilege escalation)
Install and Remove Packages with Ansible
Installing a Package
Try installing nano on your CentOS host:
Expected Output:
Use
-b(become) for root privileges, similar tosudo.
Checking Idempotency
Run the same command again:
Output will confirm the package is already installed:
Removing a Package
To uninstall nano:
Output:
Install and Manage Apache (httpd) with Ansible
Install Apache Web Server
If Apache is already installed:
Restart Apache Service
Output:
Host a Website with Ansible
Download a Free HTML Template
Copy Website Files to Apache Directory
Use the copy module to deploy your website:
Output:
Verify Website
Open your browser and go to:
You should see the Pixie HTML template displayed via Apache.
Summary of Key Commands
| Task | Module | Command Example |
|---|---|---|
| Test connectivity | ping | ansible -m ping |
| Install a package | yum | ansible -b -m yum -a "name=nano state=present" |
| Remove a package | yum | ansible -b -m yum -a "name=nano state=absent" |
| Restart service | service | ansible -b -m service -a "name=httpd state=restarted" |
| Copy files | copy | ansible -b -m copy -a "src=... dest=..." |
Conclusion
You have successfully:
Installed Ansible on Ubuntu
Created a custom inventory file
Used ad-hoc commands to manage CentOS remotely
Automated package management and Apache web hosting
With these basics, you’re ready to move on to Ansible Playbooks for larger automation projects such as configuration management, deployments, and monitoring setups.
Next Lesson
























To learn more about our affordable advertising options and how they can benefit your website, visit — rb.gy/34p7i3?Voict today. Your success is our priority!
look at more info https://drathenhill.com
Минеральные удобрения – это незаменимые помощники в современном сельском хозяйстве, призванные обеспечить растения необходимыми питательными веществами для полноценного роста, развития и обильного урожая. Они представляют собой неорганические соединения, содержащие элементы, необходимые для жизни растений: азот, фосфор, калий и другие микроэлементы. Подскажите где взять уралхим удобрения