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
🖥️ Step 1 — Provision Control Server Provision an Ubuntu instance in the default AWS VPC (Sydney region).
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@
⚙️ Step 2 — Install Ansible Install ansible with command - sudo apt install ansible
🖥️ 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
Provisioned a second ubuntu instance (target instance)
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
The screenshot above shows a failed ssh connection
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)
🔐 Step 5 — Enable Passwordless Authentication on Target Node On the target instance, repeat:
ssh-keygen ls ~/.ssh/
Open the authorized_keys file:
vim ~/.ssh/authorized_keys
Copy the public key from the first instance
paste the public key from the control server.
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.
⚙️ 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.
For one IP instance/server use the following command:
![]()
For multiple IP instances/servers use the following command:
![]()
The command below is used to create a file in the target server:
![]()
Ansible indicates a change has occurred and the yellow lines means everything is good, a red line will indicate an error has occurred.
![]()
The screenshot indicates the devopsclass file was created in the target instance/server.

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.

Check disk info: ansible all -a "df -h"
The command indicates information on the target instance/server disc.
Grouping servers enables teams to use a different set of servers illustrated in the screenshot above.
📘 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.
Run the Playbook: ansible-playbook install-nginx.yml
(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:
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.
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.
📂 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>
Roles provide a structured directory layout with:
tasks/ handlers/ templates/ vars/ files/
📌 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
