Giter Club home page Giter Club logo

ansible_project's Introduction

AUTOMATION USING ANSIBLE PLAYBOOKS

image

The Pledge

Created 3-4 EC2 t2.micro instances using the Amazon Machine Image as Ubuntu, designated one of them as the host/master server and the others are termed as nodes. The host server will eventually roll out the updates and changes to the nodes using Ansible which is an Infrastructure as a Code tool. After the instances are up and running, the following commands are used to install Ansible :

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

Note: The following commands may differ according to the AMI used to create the instance(s)

The following command is used to export the key-pair login file to the host server :

 scp -i <key-pair.pem> key-pair.pem [email protected]:/home/ubuntu/.ssh

We need to include the host servers' IP Addresses and the key that was imported earlier in the host file using the following command :

 sudo nano /etc/ansible/hosts

After doing the following tasks the file should be like this

2023-04-16 (3)

And give the hosts file read access using :

 chmod 600 <key-pair.pem>

The Turn

So, the stage is set for the act, but we should perform a final check to be sure. Using the following commands :

 ansible servers -m ping

All the servers should return a "pong" to your request.

Now, before creating the playbooks, we can perform some actions using the module (-m) and the (-a) tag such as :

 ansible servers -a "sudo apt update"

Accordingly, this command rolls all the available updates in all the node servers. You can try using other modules from the given link :

https://docs.ansible.com/ansible/2.9/modules/list_of_all_modules.html

An Ansible playbook is a file containing a series of tasks and configurations to be executed on remote hosts. Here is an example of a basic Ansible playbook:

---
- name: My playbook
 hosts: my_hosts
 become: true
 vars:
   my_var: "my_value"
 tasks:
   - name: Install packages
     apt:
       name:
         - package1
         - package2
       state: present

   - name: Create directory
     file:
       path: /my/directory
       state: directory
       owner: root
       group: root
       mode: '0755'

   - name: Copy file
     copy:
       src: /path/to/local/file
       dest: /path/to/remote/file
       owner: root
       group: root
       mode: '0644'

Inventories are created namely development and production to group the remote servers accordingly and also to deploy certain actions according to the need.

The Prestige

The final part i.e. rolling out the actions to the required servers.

ansible-playbook <playbook_name>.yaml

You can now check the required server instances to see if the playbooks work properly.

ansible_project's People

Contributors

rajdeep1311 avatar riteshpaul3 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.