Skip to content

Commit 7fd9429

Browse files
committed
Setting up control node and target node using ansible
1 parent e9fffe9 commit 7fd9429

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Setting Up Control Node and Target Nodes Using Ansible 🌐🔧
2+
3+
## Overview
4+
5+
This guide provides step-by-step instructions to set up a control node and two target nodes using Ansible, a powerful automation tool. Ansible simplifies the management and configuration of multiple nodes from a single control node.
6+
7+
## Prerequisites 📋
8+
9+
- Control node and target nodes accessible over SSH
10+
- Ansible installed on the control node
11+
- Basic understanding of Ansible concepts (inventory, playbooks, etc.)
12+
13+
## Step-by-Step Guide 🛠️
14+
15+
### Step 1: Install Ansible on Control Node
16+
17+
1. **Update the package repository**:
18+
19+
```sh
20+
sudo apt update
21+
22+
2. **Install Ansible:**
23+
```sh
24+
sudo apt install ansible
25+
26+
3. **Verify Ansible installation:**
27+
```sh
28+
ansible --version
29+
30+
### Step 2: Configure SSH Access
31+
32+
1. **Generate SSH keys on the control node (if not already done):**
33+
```sh
34+
ssh-keygen
35+
36+
2. **Copy the SSH public key to the target nodes:**
37+
```sh
38+
ssh-copy-id user@target-node1
39+
ssh-copy-id user@target-node2
40+
```
41+
Replace user with your username and target-node1, target-node2 with the respective IP addresses or hostnames of your target nodes.
42+
43+
3. **Verify SSH connectivity to target nodes:**
44+
```sh
45+
ssh user@target-node1
46+
ssh user@target-node2
47+
48+
### Step 3: Configure Ansible Inventory
49+
50+
1. **Create an Ansible inventory file (e.g., hosts.ini) on the control node:**
51+
```ini
52+
[targets]
53+
target-node1 ansible_host=ip_address1
54+
target-node2 ansible_host=ip_address2
55+
56+
[targets:vars]
57+
ansible_user=user
58+
```
59+
Replace ip_address1, ip_address2 with the IP addresses or hostnames of your target nodes, and user with your SSH username.
60+
61+
### Step 4: Write Ansible Playbook
62+
63+
**Create an Ansible playbook (e.g., setup.yml) to configure the target nodes:**
64+
```yaml
65+
---
66+
- hosts: targets
67+
tasks:
68+
- name: Ensure NTP (Network Time Protocol) is installed
69+
package:
70+
name: ntp
71+
state: present
72+
73+
```
74+
Customize the playbook tasks according to your requirements.
75+
76+
### Step 5: Run Ansible Playbook
77+
78+
1. **Execute the Ansible playbook from the control node:**
79+
```sh
80+
ansible-playbook -i hosts.ini setup.yml
81+
82+
2. **Verify configuration on target nodes:**
83+
```sh
84+
ssh user@target-node1
85+
systemctl status ntp
86+
87+
Repeat for target-node2.
88+
89+
### Conclusion 🎉
90+
91+
You have successfully set up a control node and configured two target nodes using Ansible. This setup enables centralized management and automation of tasks across your infrastructure.
92+
93+
94+
95+
96+

0 commit comments

Comments
 (0)