Saturday, 8 August 2026

How to manage WSL and Ansible automation

Question : How to manager WSL
To manage and maintain Windows Subsystem for Linux (WSL), use the wsl command-line utility in Windows PowerShell or Command Prompt. The core shutdown command is wsl --shutdown, while maintenance tasks use options like --terminate, --export, and --set-version
Shutdown Commands
  • Shut down all running distributions and the WSL 2 lightweight utility VM: wsl --shutdown
  • Stop a single specific Linux distribution: wsl --terminate <DistributionName> (or wsl -t <DistributionName>) 
Maintenance & Management Commands
  • List all installed distributions and check if they are running or stopped: wsl --list --verbose (or wsl -l -v)
  • Change a distribution version between WSL 1 and WSL 2: wsl --set-version <DistributionName> <Version>
  • Backup or export a distribution to a tar file for maintenance: wsl --export <DistributionName> <FileName.tar>
  • Restore or import a distribution from a tar backup file: wsl --import <DistributionName> <InstallLocation> <FileName.tar>
  • Completely remove and delete a distribution and its data: wsl --unregister <DistributionName> 


 To install Docker Engine on Ubuntu, the recommended approach is to set up Docker's official repository and install the native packages. This ensures you get the latest stable version and security updates. 

1. Clear Old Versions
Remove conflicting or older versions before starting: 
bash
sudo apt-get remove docker docker-engine docker.io containerd runc
Use code with caution.
2. Set Up the Repository
Install required tools and add Docker's official GPG key to verify packages: 
bash
# Update package index
sudo apt-get update

# Install prerequisites
sudo apt-get install ca-certificates curl gnupg -y

# Add the official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to APT sources
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Use code with caution.
3. Install Docker Engine
Update the repository indexes and install Docker alongside Docker Compose
bash
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

Wednesday, 29 July 2026

Automating Oracle Exadata health checks via Python

 

  • Q: How do you connect Python to an Oracle Database without thick client libraries?
    • A: Use the modern oracledb module in Thin mode (default), which does not require installing Oracle Instant Client.
  • Q: How do you safely manage database passwords in automated scripts?
    • A: Use Python's built-in getpass module or pull credentials dynamically from secure environment variables via os.environ.

  • Question : Python for Exadata: Health Check Task Example

  • or
  • Step-by-Step Implementation
    1. Install Library: Run pip install oracledb.
    2. Import and Connect: Establish a secure connection pool or single connection using credentials.
    3. Execute Query: Fetch critical alerts from V$ALERT_TYPES or GV$DIAG_ALERT_EXT.
    4. Close Connection: Safely release database handles.
    python
    import oracledb
    import sys
    
    def check_exadata_alerts(user, password, dsn):
        try:
            connection = oracledb.connect(user=user, password=password, dsn=dsn)
            cursor = connection.cursor()
            sql = "SELECT MESSAGE_TEXT FROM GV$DIAG_ALERT_EXT WHERE ORIGINATING_TIMESTAMP > SYSDATE - 1 AND MESSAGE_TEXT LIKE '%ORA-%'"
            cursor.execute(sql)
            alerts = cursor.fetchall()
            return alerts
        except Exception as e:
            print(f"Connection failed: {e}")
            sys.exit(1)
        finally:
            cursor.close()
            connection.close()
    
    Test Cases
    • Test Case 1 (Positive): Pass valid Exadata/Oracle DSN and credentials; assert return type is a list.
    • Test Case 2 (Negative): Pass invalid password; assert exception handling catches oracledb.DatabaseError and exits gracefully without crashing.
    • Test Case 3 (Boundary): Zero critical alerts found; assert function returns an empty list [] instead of None.
  • Python for Exadata: Health Check Task Example
    Step-by-Step Implementation
    1. Install Driver: Run pip install oracledb.
    2. Establish Connection: Connect to the database using Thin mode.
    3. Run Query: Query storage cell metrics or alert logs.
    4. Process Output: Fetch and parse results.
    python
    import oracledb
    
    def check_exadata_cells(user, password, dsn):
        connection = oracledb.connect(user=user, password=password, dsn=dsn)
        cursor = connection.cursor()
        # Query checking ASM diskgroup or cell status mock view
        cursor.execute("SELECT CELL_NAME, STATUS FROM V$SMART_SCAN_METRIC") 
        results = cursor.fetchall()
        cursor.close()
        connection.close()
        return results
    
    Test Cases
    • Positive Test Case: Valid credentials and active Exadata grid return a list of tuples with ONLINE status.
    • Negative Test Case: Invalid DSN or incorrect credentials trigger a oracledb.DatabaseError, which is caught via exception handling.
    • Boundary Test Case: Empty result set when no cells match criteria returns an empty list without throwing an index error.