Giter Club home page Giter Club logo

ansible's Introduction

Ansible

Instead of installing software manually in client/server machine manually will be using ansible for that in automated way.

For example: Need to install java and Maven in multiple machin, we can use ansible.

But with ansible just do the 
  >>  ssh setup between master and client machine where you want to do the configuration in automated way.
  >> create inventory file or host file which will be understanable by ansible and it will connect to those server and perform tasks.

Creating three servers:
====================  
  server 1    ===> master
  server 2 ,3 ==> node

Steps:

    Step 1:   Generate ssh key on master and copy pub key of master to all node/client/slave machines.

image image

image image image

Check if you are able to login node1 and node2 from master with ssh:

image image

    Step 2:   Install ansible only on master and not on nodes
    
    In master:
    
        amazon-linux-extras install ansible2

image image

        check the ansible installation is done properly:

image

    Step 3:   create inventory file(either in /stc/ansible/ or in your local path-->name of the file -hosts) for mentioning the ipaddr of node machine
              
              /etc/ansible/hosts -- is called inventory file
    
              -- We will create a grouping 
              
                [webservers]
                node1ip
                node2ip

image

              -- its possible to give domain name in inventory file but location should be placed in /etc/hosts
    
    
    Step 4: Check with ping command in ansible for webservers connection

image

    Step 5: Play with Ansible adhoc commands for better understanding
    
     (Sample adhocs are >> Rebooting server >>managing files >> Managing Packages >> Managing user & groups >> Managing services >>Gathering facts)
     
     Sample adhoc for java installation:

    command: ansible -m yum -a 'name=java-1.8.0-openjdk state=present' webservers

image

    get_url:    ansible -m get_url -a 'url=https://downloads.apache.org/tomcat/tomcat-8/v8.5.61/bin/apache-tomcat-8. dest=/opt mode=0777' webservers

    unarchive:  ansible -m unarchive -a 'src=/opt/apache-tomcat-8.5.61.tar.gz dest=/opt remote_src=yes' webservers

Install httpd with ansible-playbook

  1. create install_httpd.yml and check the syntax check

image

After correction:

image

2 Run :

ansible-playbook install_httpd.yml

image

  1. Service start added in install_httpd.yml:

image

For tomcat ---> place the tomcat.service under the folder where your ansible yml is saved.

Or else will get the below error,

image

image

Check the tomcat service in node:

image

ansible_practice1.yml:

- name: sample
  hosts: webservers
  remote_user: root   ===> remote user is root
  become: true        ===>  allowing root user to execute this playbook, if false then permission denied to remote user for execution 

  • name: sample hosts: webservers remote_user: root become: false tasks:
    • name: install yum : name: maven state: latest
    • name: Checking command: echo 'Heloo'

Execute with -v so that we could see the echo command:

Command: ansible-palybook -v ansible_practice1.yml --syntax-check

image

image

Execute with -m for webserver(etc/ansible/hosts):

image

Variable .yml:

image

image

Variable with two variables:

image

image

Variable usage:

image

Variable with runtime value:

image

lineinline ---to add line in file:

image

Run docker container using ansible playbook (docker and docker-py is mandatory to run container:

image

    Run https://github.com/logambigaik/ansible/blob/main/install-dockerpkg-in-ansible.yml to fix the issue.

docker-container:

Instal docker with pip  -for docker login issue

    - hosts: localhost
      tasks:
      - name: create
        docker_container:
            name: webappcontainer
            image: klogambigai/stackdemo:latest
            state: present
            exposed_ports:
            - 8000:80

image

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.