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.
- Control node and target nodes accessible over SSH
- Ansible installed on the control node
- Basic understanding of Ansible concepts (inventory, playbooks, etc.)
-
Update the package repository:
sudo apt update
-
Install Ansible:
sudo apt install ansible
-
Verify Ansible installation:
ansible --version
-
Generate SSH keys on the control node (if not already done):
ssh-keygen
-
Copy the SSH public key to the target nodes:
ssh-copy-id user@target-node1 ssh-copy-id user@target-node2
Replace user with your username and target-node1, target-node2 with the respective IP addresses or hostnames of your target nodes.
-
Verify SSH connectivity to target nodes:
ssh user@target-node1 ssh user@target-node2
- Create an Ansible inventory file (e.g., hosts.ini) on the control node:
Replace ip_address1, ip_address2 with the IP addresses or hostnames of your target nodes, and user with your SSH username.
[targets] target-node1 ansible_host=ip_address1 target-node2 ansible_host=ip_address2 [targets:vars] ansible_user=user
Create an Ansible playbook (e.g., setup.yml) to configure the target nodes:
---
- hosts: targets
tasks:
- name: Ensure NTP (Network Time Protocol) is installed
package:
name: ntp
state: present
Customize the playbook tasks according to your requirements.
- Execute the Ansible playbook from the control node:
ansible-playbook -i hosts.ini setup.yml
- Verify configuration on target nodes:
ssh user@target-node1 systemctl status ntp
Repeat for target-node2.
You have successfully set up a control node and configured two target nodes using Ansible.