Learning Ansible

Week 1 - 27/12/2024



 Ansible is an open-source automation tool used for configuration management, application deployment, and task automation. It simplifies complex IT tasks by automating repetitive processes, making it easier to manage large-scale systems.

Key Features of Ansible

  • Agentless: Unlike other automation tools, Ansible does not require any agent software to be installed on the managed nodes. It uses SSH for communication, making it lightweight and easy to set up.

  • Declarative Language: Ansible uses a simple, human-readable language called YAML (Yet Another Markup Language) to define automation tasks. This makes it accessible to both developers and system administrators.

  • Idempotency: Ansible ensures that tasks are idempotent, meaning they can be run multiple times without changing the system's state if it is already in the desired state.

  • Extensible: Ansible has a modular architecture, allowing users to extend its functionality with custom modules, plugins, and roles.

Use Cases

  • Configuration Management: Ansible can manage the configuration of servers, ensuring they are set up consistently and correctly.

  • Application Deployment: Automate the deployment of applications across multiple servers, reducing the risk of human error.

  • Orchestration: Coordinate complex workflows and processes across different systems and environments.

  • Provisioning: Set up and configure new servers and infrastructure components.

Getting Started with Ansible

  1. Install Ansible: You can install Ansible using package managers like pip, apt, or yum. For example, to install Ansible using pip, run:

    bash
    pip install ansible
    
  2. Create an Inventory File: An inventory file lists the hosts and groups of hosts that Ansible will manage. Here's an example of a simple inventory file:

    ini
    [webservers]
    web1.example.com
    web2.example.com
    
    [dbservers]
    db1.example.com
    db2.example.com
    
  3. Write a Playbook: A playbook is a YAML file that defines the tasks Ansible will perform on the managed hosts. Here's an example of a basic playbook:

    yaml
    ---
    - name: Install and configure web server
      hosts: webservers
      become: yes
      tasks:
        - name: Install Apache
          apt:
            name: apache2
            state: present
    
        - name: Start Apache service
          service:
            name: apache2
            state: started
            enabled: yes
    
  4. Run the Playbook: Use the ansible-playbook command to run the playbook:

    bash
    ansible-playbook -i inventory playbook.yml
    

Benefits of Using Ansible

  • Simplicity: Ansible's straightforward syntax and agentless architecture make it easy to learn and use.

  • Scalability: Ansible can manage thousands of nodes efficiently, making it suitable for large-scale environments.

  • Flexibility: Ansible can be used for a wide range of automation tasks, from simple configuration management to complex orchestration

Why Use Ansible Rather than Jenkins 

  1. Configuration Management: Ansible excels in configuration management, automation, and orchestration, while Jenkins is primarily a CI/CD tool.

  1. Agentless Architecture: Ansible operates without the need for agents on target machines, simplifying setup and reducing overhead.

  2. Ease of Use: Ansible uses a simple, human-readable YAML syntax, making it easier to write and understand automation scripts.

  3. Idempotency: Ansible ensures tasks are idempotent, maintaining consistency in your infrastructure.

  4. Integration: Ansible integrates well with a wide range of tools and platforms, focusing on infrastructure management and automation.

  5. Declarative Approach: Ansible follows a declarative approach, defining the desired state, while Jenkins follows an imperative approach, defining the steps to be executed


    As I use Jenkins for Work, it was a refreshing to learn Ansible for Deployments.



Week 2 - 27/12/2024


Learning NodeJS and moving into DENO



What is

  • Runtime Environment: is built on Chrome's V8 JavaScript engine, enabling you to run JavaScript code outside of a web browser.

  • Event-Driven: It uses an event-driven, non-blocking I/O model, making it efficient and suitable for real-time applications.

  • Single-Threaded: Despite being single-threaded, can handle many connections simultaneously thanks to its asynchronous nature.

Key Features

  • NPM (Node Package Manager): A vast library of open-source packages that you can use to extend the functionality of your applications.

  • Asynchronous Programming: uses callbacks, promises, and async/await to handle asynchronous operations.

  • Modules: has a module system that allows you to organize your code into reusable components.

Use Cases

  • Web Servers: is commonly used to build web servers and APIs.

  • Real-Time Applications: Ideal for applications that require real-time communication, such as chat apps and online gaming.

  • Microservices: is well-suited for building microservices due to its lightweight and modular nature.

Getting Started

  1. Install : Download and install from the .

  2. Create a Project: Initialize a new project using npm init and create a package.json file.

  3. Write Your First Script: Create a simple JavaScript file, such as app.js, and write your first code.

Example Code

Here's a simple example of a server:

javascript
const http = require('http');

const server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Hello, World!\n');
});

const port = 3000;
server.listen(port, () => {
    console.log(`Server running at http://localhost:${port}/`);
});

This code creates a basic HTTP server that listens on port 3000 and responds with "Hello, World!" when accessed








Using Deno for a NodeJS replacement,

Deno is a modern runtime for JavaScript and TypeScript, created by Ryan Dahl, the original developer of It was designed to address some of the shortcomings of and to provide a more secure and efficient environment for running JavaScript and TypeScript code. Here are some advantages of Deno over Node.js:

  1. Security: Deno has a secure-by-default approach. It runs code in a sandboxed environment and requires explicit permissions for file system access, network access, and environment variables. This reduces the risk of security vulnerabilities.

  2. TypeScript Support: Deno has built-in support for TypeScript, allowing you to write and run TypeScript code without the need for additional tools or configuration. This makes it easier to work with TypeScript out of the box.

  3. Simplified Dependency Management: Deno uses URL-based imports for dependencies, eliminating the need for a separate package manager like npm. This simplifies dependency management and reduces the risk of dependency-related issues.

  4. Standard Library: Deno comes with a standard library that is audited and maintained by the Deno team. This ensures a consistent and reliable set of APIs for common tasks, reducing the need for third-party libraries.

  5. Modern Features: Deno leverages modern JavaScript features and web standards, making it more aligned with current web development practices. It also includes built-in development tooling, such as a linter, formatter, and test runner.

  6. Single Executable: Deno is distributed as a single executable file, making it easy to install and use without the need for additional setup or configuration.

While Deno offers several advantages, it's important to consider your specific use case and requirements when choosing between Deno and has a mature ecosystem, extensive community support, and a vast library of packages, which can be beneficial for many projects.


Getting Deno Working

Getting Started with Deno

  1. Installation:

    • Windows: Use the PowerShell command:

      sh
      iwr https://deno.land/x/install/install.ps1 -useb | iex
      
    • macOS/Linux: Use the shell command:

      sh
      curl -fsSL https://deno.land/x/install/install.sh | sh
      
  2. Running a Script:

    • Create a simple TypeScript file, hello.ts:

      ts
      console.log("Hello, Deno!");
      
    • Run the script using Deno:

      sh
      deno run hello.ts
      
  3. Permissions:

    • Deno is secure by default. To allow network access, use the --allow-net flag:

      sh
      deno run --allow-net server.ts
      
  4. Importing Modules:

    • Deno uses URL-based imports. For example:

      ts
      import { serve } from "https://deno.land/std@0.95.0/http/server.ts";
      
  5. Standard Library:

    • Deno comes with a standard library that you can use without additional dependencies. Check out the for more information.

  6. Development Tools:

    • Deno includes built-in tools like a linter, formatter, and test runner. You can use them as follows:

      sh
      deno lint
      deno fmt
      deno test
      

Deno offers a secure, modern, and efficient environment for JavaScript and TypeScript development.










Setting Up Pip for Python 3 on Ubuntu 24.04 and Above .

Setting Up PIP for Python 3+ on Ubuntu 24 and Above Using pip.conf

Setting Up PIP for Python 3+ on Ubuntu 24 and Above Using pip.conf

Introduction

This guide will walk you through the steps to get PIP install commands working for Python 3+ on Ubuntu 24 and above, using the pip.conf configuration file. In this the Pip Configuration is created because newer versions dont allow PIP packages to be installed from anysite, but the APT repo accepted libraries only

Step 1: Install Python 3 and PIP

  1. Update System Packages:
    sudo apt update
    sudo apt upgrade
  2. Install Python 3 (if not already installed):
    sudo apt install python3
  3. Install PIP for Python 3:
    sudo apt install python3-pip
  4. Verify PIP Installation:
    pip3 --version

Step 2: Configure pip.conf

  1. Create or Edit pip.conf:

    Create the pip.conf file in the appropriate directory. For user-specific configuration, create it in ~/.config/pip/. For global configuration, create it in /etc/pip/.

  2. Add Configuration Settings:

    Open the pip.conf file in a text editor and add the following settings:

    [global]
    break-system-packages = true
    

Step 3: Using PIP with the Configuration

  1. Install a Python Package:
    pip3 install <package-name>
  2. Upgrade a Python Package:
    pip3 install --upgrade <package-name>
  3. Uninstall a Python Package:
    pip3 uninstall <package-name>

Conclusion

By following these steps, you can ensure that PIP install commands work seamlessly for Python 3+ on Ubuntu 24 and above, using the pip.conf configuration file. This setup will help you manage Python packages efficiently and avoid common issues related to package installations.

Feel free to reach out if you need any further assistance! 🚀