Day 1: Ansible Installation and SSH Connection Setup

Day 1: Ansible Installation and SSH Connection Setup

Ansible Installation on Master Node:

Architecture:

Access the master node:

  1.   Copy codecd ~/.ssh
    

Generate SSH key pairs:

  1.   ssh-keygen
    

Display the public key:

  1.   cat id_rsa.pub
    
  2. Copy the displayed key (id_rsa.pub) and paste it on the child node.

Access the child node:

  1.   cd ~/.ssh
    

Edit the authorized_keys file:

  1.   vi authorized_keys
    
  2. Paste the master node's public key into the authorized_keys file.

SSH into the master node from the child node:

  1.   ssh username@child_node_ip
    

Update the child node:

  1.   sudo apt -y update
    

Install Ansible on the master node:

  1.   sudo apt install software-properties-common
      sudo apt-add-repository --yes --update ppa:ansible/ansible
      sudo apt install ansible
    

Verify the Ansible installation:

  1.   ansible --version
    

Configuring SSH Connections in Ansible:

  1. Navigate to the Ansible configuration directory:

     cd /etc/ansible
    

Edit the inventory file:

  1.   vi hosts
    

Define groups and add child nodes' IPs or hostnames:

  1.   [group_name]
      child_node_ip_or_hostname
    
  2. Save and exit the file.

Test the SSH connection to all nodes:

  1.   ansible group_name -m ping
    

  1. Display the inventory in YAML format:

     ansible-inventory --list --yaml
    

Additional Reference:

This comprehensive guide covers the installation of Ansible on both the master and child nodes, setting up SSH connections, and verifying the setup. Replace group_name, child_node, child_node_ip, and your_username with your actual details. This ensures a seamless and secure Ansible configuration for effective server management.

Did you find this article valuable?

Support Aqib Hafeez(DevOps enthusiast) by becoming a sponsor. Any amount is appreciated!