Skip to content

ITLab-CC/Ansible-Collection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansible Installation & Usage Guide

Introduction

Ansible is an open-source automation tool that can help you with configuration management, application deployment, task automation, and even IT orchestration.

Installation

Prerequisites

  • A Linux-based system (e.g., Ubuntu, CentOS)
  • Python installed (Ansible is written in Python)

Installation Steps

Ubuntu

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

CentOS

sudo yum install epel-release
sudo yum install ansible

Basic Usage

  1. Inventory File: Before you can use Ansible, you need to have an inventory file. This file lists all the hosts you want to manage with Ansible. Create a file named hosts.ini and add your servers:
[server]
192.168.1.10
192.168.1.11

[db]
192.168.1.20
  1. Ping All Hosts: To check if Ansible can communicate with all the servers listed in the inventory file, use the ansible command:
ansible -i hosts.ini all -m ping
  1. Ad-hoc Commands: You can run commands on your servers without writing a playbook. For example, to check the disk space on all web servers:
ansible -i hosts.ini web -m shell -a 'df -h'
  1. Playbooks: Playbooks are the heart of Ansible. They are written in YAML and describe the tasks you want Ansible to execute. Here's a simple playbook to ensure the latest version of Apache is installed:
---
- hosts: web
  tasks:
    - name: Ensure Apache is installed
      apt:
        name: apache2
        state: latest

To run the playbook:

ansible-playbook -i hosts.ini playbook.yaml

About

This is a collection of useful ansible scripts

Topics

Resources

Stars

Watchers

Forks