Skip to content

baba2undexlxye/Ansible-Installation-Deployment-Guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Ansible-Installation-Deployment-Guide


This project sets up a basic Ansible control node and a target node, enabling automated server configuration using Ansible. You will:

Provision two Ubuntu instances

Install Ansible

Configure passwordless SSH authentication

Execute Ansible ad-hoc commands

Create and run Ansible playbooks

Understand inventory management, verbosity, and Ansible roles

🖥️ Step 1 — Provision Control Server Provision an Ubuntu instance in the default AWS VPC (Sydney region).

image

SSH into the instance via port 22 using Mo and ran the command sudo apt update to fetch the latest information about available packages and updates.

ssh ubuntu@

image image

sudo apt update

⚙️ Step 2 — Install Ansible Install ansible with command - sudo apt install ansible

image

Run the command ansible --version to see that ansible had been install on the VM and the version image

🖥️ Step 3 — Provision Target Server Create a second Ubuntu instance in the same VPC.

The first server = Ansible control node

The second server = Ansible target node

image Provisioned a second ubuntu instance (target instance) image

There are two instances running in the default VPC  The first ubuntu server will be used to configure the target ubuntu server  Ansible requires a PASSWORDLESS authentication, so SSH key pairs must be configured.

🔐 Step 4 — Configure Passwordless Authentication (Control Node)

Generate SSH keys: ssh-keygen

image

The screenshot above shows a failed ssh connection

image o The command ssh-keygen generates a new SSH key pair (a public and private key) used for a secure authentication.

The keys are stored in: /home/ubuntu/.ssh/ ├── id_rsa # private key (keep safe) └── id_rsa.pub # public key (share with targets)

⚠️ Never share the private key. ✔️ Use the public key to authenticate to other machines.

🔐 Step 5 — Enable Passwordless Authentication on Target Node On the target instance, repeat:

ssh-keygen ls ~/.ssh/

image

Open the authorized_keys file:

vim ~/.ssh/authorized_keys

image

Copy the public key from the first instance

image

paste the public key from the control server.

image

SSH into the target instance from the first instance without any defined keys. This is possible because the public keys from the first instance had been copied into the authorized_keys file on the target instance enabling for a PASSWORDLESS authentication and connection.

image

Passwordless authentication is now enabled — a requirement for Ansible automation.

⚙️ Step 6 — Using Ansible Ad-Hoc Commands

Ad-hoc commands allow quick, simple operations without using a playbook.

o To create task with ansible without using playbook, task(s) can be created in the target instance/server examples files by running ansible commands known as Ansible Adhoc Commands o To run ansible adhoc command(s) can be completed with inventory file (inventory file is the location that stores the IP addresses of the target instance(s)/server(s)). o By default, ansible stores inventory in /etc/ansible/hosts (default file for ansible) but it is not always convenient to use it from here.

image

For one IP instance/server use the following command: image

For multiple IP instances/servers use the following command: image

The command below is used to create a file in the target server: image

Ansible indicates a change has occurred and the yellow lines means everything is good, a red line will indicate an error has occurred. image

The screenshot indicates the devopsclass file was created in the target instance/server. image

Note – ansible adhoc commands is for simple task (like the above task) and ansible playbook is for more complex tasks. For more information check https://docs.ansible.com/

This command shows the number of processes on the target instance/server indicating the server has only 1(one) CPU. image

Check disk info: ansible all -a "df -h"

image

The command indicates information on the target instance/server disc.

image

Grouping servers enables teams to use a different set of servers illustrated in the screenshot above.

image

DB server information as highlighted in the command.

📘 Step 7 — Building an Ansible Playbook

Ansible Playbook example - install Nginx, restart nginx, to accomplish this task a playbook is written as illustrated with the screenshot below. The yml indicates it is a YAML file which an ansible playbook is written.

image

Run the Playbook: ansible-playbook install-nginx.yml

image

(The screenshot above shows a complete/correct ansible-playbook execution).

From the screenshot the first task that was executed by ansible-playbook was i. gathering facts, ii. followed by Install nginx iii. and start nginx.

Verify nginx:

image

The screenshot above shows that nginx is running on the target instance/server with the command sudo systemctl status nginx

To increase the verbosity, add -vvv (the number of Vs will determine levels of verbosity.

image

Note:

This is a basic installation for using ansible to install nginx and start it (nginx) in a target server. There are cases where you can use ansible to configure your Kubernetes clusters like in job environment.

image

📂 Ansible Roles (For Complex Projects)

For large automation tasks (e.g., Kubernetes cluster setup with 60–80 tasks), use Ansible roles to organize code.

Create a new role:

ansible-galaxy role init <role_name>

image

Roles provide a structured directory layout with:

tasks/ handlers/ templates/ vars/ files/

image

This makes large automation projects more scalable and maintainable.

📌 Summary

This project demonstrated:

Setting up an Ansible control node and target node

Configuring secure passwordless SSH

Using Ansible ad-hoc commands

Writing and executing playbooks

Understanding roles for large-scale automation

Ansible is a powerful automation tool useful for DevOps, cloud operations, and infrastructure orchestration at scale.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors