Code Monkey home page Code Monkey logo

ansible-101's Introduction

Ansible-101

This repository contains the code for the Ansible 101 workshop.

Prerequisites

  • Ansible 2.2 or higher

Setup

  • Clone this repository

Perform these commands in master node:

  • sudo apt-get update
  • sudo -i
  • apt-get install python3
  • apt-get install python3-pip
  • python3 --version
  • pip3 --version or pip --version
  • apt-get update
  • apt-get install software-properties-common
  • apt-add-repository ppa:ansible/ansible
  • apt-get update
  • apt-get install ansible
  • ansible --version

Add hosts to /etc/ansible/hosts -

  • vi /etc/ansible/hosts
[web]
192.168.2.1
192.168.2.2
  • ansible all --list-hosts - to check if hosts are added

  • ssh-keygen

  • cat /root/.ssh/id_rsa.pub

Add the public key to the remote hosts

Here we are going to add the copied key to the slave nodes.

  • login to the slave nodes
  • vi /root/.ssh/authorized_keys or sudo vi /root/.ssh/authorized_keys
  • paste the copied key in both the slave nodes

Perform these commands in master node:

  • ssh then enter yes - to check if the connection is established, and you will be logged in to the slave node, do same for the other slave node

  • ansible all -m ping - to check if the connection is established

  • ansible all -m shell -a "free -m" - to check the memory of the slave nodes.

  • ansible all -m shell -a "df -h" - to check the disk space of the slave nodes.

  • ansible all -m shell -a "uptime" - to check the uptime of the slave nodes.

  • ansible all -m shell -a "cat /etc/os-release" - to check the OS of the slave nodes.

  • ansible all -m shell -a "cat /etc/hostname" - to check the hostname of the slave nodes.

Setup ansible.cfg

  • vi /etc/ansible/ansible.cfg
[defaults]
inventory = /etc/ansible/hosts
host_key_checking = False

Create Playbook

  • vi playbook.yml
---
- name: Install nginx 
  hosts: web  
  tasks:    
    - name: install nginx 
      apt: 
        name: nginx
        state: latest
        update_cache: yes
    - name: start nginx 
      service:
        name: nginx 
        state: started 
  • ansible-playbook playbook.yml - to run the playbook

  • ansible-playbook playbook.yml --check - to check the playbook

  • Check the nginx installation in the slave nodes, go to the browser and type the ip of the slave nodes, you will see the nginx welcome page.

if the page is not displayed, then check the inbound rules in the security group of the slave nodes.

These are inbound rules:

  • HTTP 80
  • Access Anywhere - IPv4
  • Access Anywhere - IPv6

This is the instruction to setup the Ansible 101 workshop.

ansible-101's People

Contributors

dark-art108 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.