DEV Community

SyedAsadRazaDevops
SyedAsadRazaDevops

Posted on

4

💻ANSIBLE Auto Configure your server for Nginx|Reactjs and Laravel|php env on ONE click👆

Let setup the ansible:

you need one "MASTER" and multiple "SLAVE" node to control the slave configuration.

Important

  • its an configuration management tool, also open-source.
  • we used "YAML" for scripting language.
  • it implement worker on "push management" model.
  • one "Master" configure multiple servers "nodes".
  • it communicate agent/nodes throw "SSH" method.
  • script are called "PLAY BOOKS".
  • the machain where ansible is installed called "ANSIBLE SERVER".
  • the set of commands to be executed in nodes/client called " MODULE"
  • metadata of servers or agent/nodes/clients called "Inventory"
  • inventory default location will be --> /etc/ansible/host

How to connect master and slave

create an SSH-KEY and paste the same in all slave servers.
So, you connect with all different nodes through IP with same private-key.

How To Install

apt install ansible
Enter fullscreen mode Exit fullscreen mode

How To Create Inventory

[servers]
server_1  ansible_hist= 1.112.113.114

[all=vars]
ansible_python_interpreter = /usr/bin/python3
Enter fullscreen mode Exit fullscreen mode

How To Check/Verify Inventory

ansible-inventory --list -y 
ansible-inventory --list -y -i [(inventory)--> /etc/ansible/host]
Enter fullscreen mode Exit fullscreen mode

How To Ping Agent/Nodes

ping the all nodes

ansible all -m ping -i [(inventory)--> /etc/ansible/host] --private-key = ~/.ssh/ansiblekey.pem

Enter fullscreen mode Exit fullscreen mode

OR

ansible all -m ping -u root
Enter fullscreen mode Exit fullscreen mode

####some use full command to get nodes info####

ansible all -a "free -h" -i [(inventory)--> /etc/ansible/host] --private-key = ~/.ssh/ansiblekey.pem

ansible all -a "uptime" -i [(inventory)--> /etc/ansible/host] --private-key = ~/.ssh/ansiblekey.pem

ansible all -a "df -h" -i [(inventory)--> /etc/ansible/host] --private-key = ~/.ssh/ansiblekey.pem
Enter fullscreen mode Exit fullscreen mode

How To Create Play-book.yml

https://www.trainwithshubham.com/blog/ansible-playbooks

    - name: This playbook will create a file
      hosts: all
      become: true
      tasks:
       - name: creating a file
         file:
         path: /home/ubuntu/testdemo2.txt
         state: touch
Enter fullscreen mode Exit fullscreen mode
    - name: This Playbook will create a user
      hosts: all
      become: true
      tasks:
       - name: Create a user Shubham
         user: name=shubham
Enter fullscreen mode Exit fullscreen mode
    - name: This playbook will install Docker
      hosts: all
      become: true
      tasks:
       - name: Add Docker GPG apt Key
         apt_key:
         url: https://download.docker.com/linux/ubuntu/gpg
         state: present

       - name: Add Docker Repository
         apt_repository:
         repo: deb https://download.docker.com/linux/ubuntu focal stable
         state: present
       - name: Install Docker
         apt:
         name: docker-ce
         state: latest
Enter fullscreen mode Exit fullscreen mode

How To Upgrade-all Server by(command)

ansible all -m apt -a "upgrade=yes update_cache=yes cache_valid_time=86400" --become  -i [(inventory)--> /etc/ansible/host] --private-key = ~/.ssh/ansiblekey.pem
Enter fullscreen mode Exit fullscreen mode

How To Run Playbook.yml

ansible-playbook playbook.yml -i [(inventory)--> /etc/ansible/host] --private-key = ~/.ssh/ansiblekey.pem 
Enter fullscreen mode Exit fullscreen mode
đź‘‹ While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay