Profile Photo

🐧 Linux Command Sheet

🌐 devopsenginer.in 🐙 GitHub 💼 LinkedIn ✉️ Email

🛠️ Ansible Deployment Setup

Project: Ansible Deployment         Date: 17/04/2025         Engineer: Parvez M B         Email: parvez@gal**intelli****.com

📦 Step 1: Set Up the Virtual Machine

apt update && apt upgrade -y 
apt install docker.io -y

🐳 Step 2: Create Docker Containers

--== Process ==--

  • Ansible-master
  • Target1:
  • Target2:
  • --== Commands below ==--

    docker run -it -d --name ansible-master ubuntu /bin/bash
    docker run -it -d --name target1 ubuntu /bin/bash
    docker run -it -d --name target2 ubuntu /bin/bash docker ps

    📦 Step 3: Configure Ansible-Master Container

    --== Process ==--

  • Login to the container:
  • Install required packages:
  • Install Software Properties Common:
  • Add Ansible Repository and Install Ansible:
  • Install Ansible:
  • Check Version to verify Ansible:
  • --== Commands below ==--

    docker exec -it ansible-master bash apt update
    apt install python-is-python3 vim iputils-ping openssh-client -y
    apt install software-properties-common
    add-apt-repository --yes --update ppa:ansible/ansible
    apt install ansible
    ansible --version

    🎯 Step 4: Configure Target Machines

    Target1 Setup

    --== Process ==--

  • Login target1 container
  • update the packages
  • Install required packages like vim python3 & ping
  • Install OpenSSH server and Client for interation.
  • --== Commands below ==--

    docker exec -it target1 bash
    apt update
    apt install vim python-is-python3 iputils-ping
    apt-get install openssh-client openssh-server -y


    Note: YOu can either install pyton3 or the minimal and point it to pyton3 using python-is-python3

    🔗 SSH Configuration

    --== Process ==--

  • Go to the directory of SSH
  • Open sshd_congig file for changes
  • Change the permission and allow Root Login 'Yes'
  • Allow the Password Auth set it to 'Yes'
  • Set the root password of the target machine
  • --== Command below ==--

    cd /etc/ssh
    vi sshd_config
    PermitRootLogin yes
    PasswordAuthentication yes
    service ssh start passwd root

    🌐 Step 5: Network & Host Setup

    --== Process ==--

  • Find ip of docker or container # Get IP (e.g., 172.17.0.3)
  • Go back to the Master node and configure details
  • Go into ansible folder to configure in master
  • edit the host file in Inventory aff target ip to host file
  • --== Commands below ==--

    docker inspect target1
    docker exec -it ansible-master bash
    cd /etc/ansible
    vi hosts # Add: 172.17.0.3


    Note: you can either use cmd to find ip

    🔐 Step 6: SSH Key Setup

                
  • Create Keygen and transfer the ssh key using ssh-copy-id user@ip to target machine. so you can ssh into it.
  • ssh-keygen
    ssh-copy-id root@172.17.0.3
    ssh root@172.17.0.3

    📜 Step 7: Create Ansible Playbook

    #Go to the path  /etc/ansible/playbooknginx.yaml 
    - hosts: all
        tasks:
          - name: Ensure nginx is installed
            apt: name: nginx
            state: latest

    🛠️ Install nginx using Ansible

    - hosts: all tasks: - name: Ensure nginx is installed apt: name: nginx state: latest

    This task installs the latest version of nginx on all target hosts using the apt module.

    Run the playbook:

    ansible-playbook playbooknginx.yaml

    🔁 Step 8: Repeat for Target2

    ✅ Deployment Verified

    🎉 Ansible installed and configured across master and targets.