Stop Wasting Time! Automate Your DevOps Environment Setup Now

Stop Wasting Time! Automate Your DevOps Environment Setup Now

When starting your DevOps journey or setting up a new environment, installing multiple tools can be time-consuming and error-prone. Wouldn't it be great if you could install all the essential tools with a single script?

Whether you’re a beginner exploring DevOps or a seasoned engineer deploying tools to a new server, this script has you covered. In this blog, we’ll walk you through a streamlined solution to set up essential DevOps tools like Docker, Terraform, AWS CLI, and more—all in one go.


Why Automate DevOps Tool Installation?

Manually installing tools takes time and requires remembering multiple commands and configurations. Automation ensures:

  • Time efficiency: Get everything up and running in minutes.

  • Consistency: Avoid version mismatches and missed dependencies.

  • Ease of reuse: Reapply the same setup across multiple servers or environments.


One-Touch Installation Script

Here’s the magic script to install tools like Docker, Terraform, MySQL Client, AWS CLI, and more on Linux-based systems. Simply copy, paste, and execute it.

#!/bin/bash

# Check if the user is root
if [[ $EUID -ne 0 ]]; then
    echo "Please run this script as root or using sudo."
    exit 1
fi

# Function to install a package
install_package() {
    PACKAGE_NAME=$1
    INSTALL_COMMAND=$2
    CHECK_COMMAND=$3

    # Check if the package is already installed
    if command -v $CHECK_COMMAND &> /dev/null; then
        echo "$PACKAGE_NAME is already installed."
    else
        echo "Installing $PACKAGE_NAME..."
        eval $INSTALL_COMMAND
        echo "$PACKAGE_NAME installed successfully."
    fi
}

# Update the package list
echo "Updating package list..."
if [[ -f /etc/debian_version ]]; then
    apt update -y && apt upgrade -y
elif [[ -f /etc/redhat-release ]]; then
    yum update -y
else
    echo "Unsupported OS."
    exit 1
fi

# Docker
install_package "Docker" \
    "curl -fsSL https://get.docker.com | bash" \
    "docker"

# Docker Compose
install_package "Docker Compose" \
    "curl -L \"https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)\" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose" \
    "docker-compose"

# Terraform
install_package "Terraform" \
    "curl -fsSL https://apt.releases.hashicorp.com/gpg | gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg && echo \"deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main\" | tee /etc/apt/sources.list.d/hashicorp.list && apt update && apt install terraform -y" \
    "terraform"

# MySQL Client
install_package "MySQL Client" \
    "apt install mysql-client -y" \
    "mysql"

# Redis CLI
install_package "Redis CLI" \
    "apt install redis-tools -y" \
    "redis-cli"

# Ansible
install_package "Ansible" \
    "apt install ansible -y" \
    "ansible"

# AWS CLI
install_package "AWS CLI" \
    "curl \"https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip\" -o \"awscliv2.zip\" && unzip awscliv2.zip && ./aws/install" \
    "aws"

# Python3 and pip3
install_package "Python3 and pip3" \
    "apt install python3 python3-pip -y" \
    "python3"

# Boto3
install_package "Boto3 (Python Library)" \
    "pip3 install boto3" \
    "python3 -c 'import boto3'"

# Ruby
install_package "Ruby" \
    "apt install ruby -y" \
    "ruby"

# Go
install_package "Go" \
    "curl -OL https://go.dev/dl/go1.20.5.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.20.5.linux-amd64.tar.gz && export PATH=\$PATH:/usr/local/go/bin && echo 'export PATH=\$PATH:/usr/local/go/bin' >> ~/.bashrc" \
    "go version"

echo "Installation completed. Please restart your shell to apply PATH changes."

Step-by-Step Instructions

  1. Save the Script: Copy the script into a file named install_devops_tools.sh.

  2. Make It Executable: Run the following command to ensure it’s executable:

     chmod +x install_devops_tools.sh
    
  3. Run the Script: Execute the script with:

     sudo ./install_devops_tools.sh
    

What Tools Does This Script Install?

This script installs the following tools with their latest stable versions:

  1. Docker: Containerization platform for deploying applications.

  2. Docker Compose: Orchestrates multi-container Docker apps.

  3. Terraform: Infrastructure as Code (IaC) tool for provisioning cloud resources.

  4. MySQL Client: Command-line client for managing MySQL databases.

  5. Redis CLI: For interacting with Redis databases.

  6. Ansible: Configuration management and application deployment tool.

  7. AWS CLI: Manage AWS services from the command line.

  8. Python3 & pip3: Programming language and package manager.

  9. Boto3: Python SDK for AWS services.

  10. Ruby: A popular programming language.

  11. Go: Open-source programming language for scalable applications.


Key Features of the Script

  • Idempotence: Ensures each tool is installed only once.

  • Error Handling: Checks if the user is running the script as root.

  • Cross-Distro Support: Supports both Debian-based (Ubuntu) and RHEL-based distributions.


What’s Next?

After running the script, you’re ready to dive into DevOps. Start using Docker for containerization, Terraform for IaC, or explore AWS services with the CLI. Need more tools? Customize the script to suit your specific requirements.


Conclusion

This script is a lifesaver for anyone who wants to save time and avoid the hassle of manual installation. Whether you’re setting up a single server or multiple environments, automating tool installation is a must for efficient DevOps workflows.

If you find this script useful, share it with your peers, and let me know in the comments what other tools you’d like to see added. Happy automating!