DEV Community

Kanav Gathe
Kanav Gathe

Posted on • Edited on

Day 15/90: Python Basics for DevOps Engineers ๐Ÿ #90DaysOfDevOps

Day 15: Python Basics for DevOps Engineers ๐Ÿš€

Hello DevOps enthusiasts! ๐Ÿ‘‹ Welcome to Day 15 of the #90DaysOfDevOps challenge. Today, we're exploring Python fundamentals essential for DevOps.

Python Installation ๐Ÿ”ง

Ubuntu Installation

# Install Python
sudo apt update
sudo apt install python3

# Verify installation
python3 --version
Enter fullscreen mode Exit fullscreen mode

Python Data Types ๐Ÿ“

1. Numbers

# Integer
server_count = 42

# Float
cpu_usage = 85.5

# Complex
complex_number = 1 + 2j
Enter fullscreen mode Exit fullscreen mode

2. Strings

# Single line string
hostname = 'web-server-01'

# Multi-line string
description = '''This is a
multi-line description
of our server'''

# String operations
print(hostname.upper())
print(hostname.split('-'))
Enter fullscreen mode Exit fullscreen mode

3. Lists (Mutable)

# Server list
servers = ['web-01', 'app-02', 'db-01']

# List operations
servers.append('cache-01')
servers.remove('db-01')
print(servers[0])  # First server
Enter fullscreen mode Exit fullscreen mode

4. Tuples (Immutable)

# Version info
version = ('Ubuntu', 20, 'LTS')
os_name, version_num, release_type = version
Enter fullscreen mode Exit fullscreen mode

5. Dictionaries

# Server details
server_info = {
    'hostname': 'web-01',
    'ip': '192.168.1.100',
    'status': 'running',
    'ram_gb': 16
}

# Access data
print(server_info['hostname'])
print(server_info.get('status'))
Enter fullscreen mode Exit fullscreen mode

6. Sets

# Unique ports
active_ports = {80, 443, 22, 3306}
active_ports.add(8080)
Enter fullscreen mode Exit fullscreen mode

7. Boolean

is_running = True
has_backup = False
Enter fullscreen mode Exit fullscreen mode

DevOps Example ๐Ÿ› ๏ธ

def check_server_status(servers):
    """Monitor server status"""
    status = {}
    for server in servers:
        # Simulate status check
        status[server] = 'running' if len(server) % 2 == 0 else 'stopped'
    return status

# Usage
servers = ['web-01', 'app-02', 'db-01', 'cache-02']
server_status = check_server_status(servers)

for server, state in server_status.items():
    print(f"Server {server} is {state}")
Enter fullscreen mode Exit fullscreen mode

Key Takeaways ๐Ÿ’ก

  • Python is essential for DevOps automation
  • Multiple data types serve different purposes
  • Lists and dictionaries are commonly used in DevOps
  • Python's simplicity makes automation easier
  • Understanding data types is fundamental

Practical Uses in DevOps ๐Ÿ”จ

  1. Script automation
  2. Log parsing
  3. API interactions
  4. Configuration management
  5. Monitoring and alerts
  6. Data processing
  7. Infrastructure automation

Python #DevOps #Automation #Programming #90DaysOfDevOps


This is Day 15 of my #90DaysOfDevOps journey. Keep coding and automating!

Top comments (1)

Collapse
 
varghesechacko profile image
Varghese Chacko • Edited

Thanks for sharing these great insights! ๐Ÿ™Œ

If you're looking to dive deeper into how Python powers real-world DevOps workflowsโ€”from automation and CI/CD to monitoring and cloud orchestrationโ€”Iโ€™ve covered it all in my book Python for DevOps. ๐Ÿš€๐Ÿ“˜

๐Ÿ“– Grab your copy here:

๐Ÿ‡ฎ๐Ÿ‡ณ BPB Store (India)

๐ŸŒ Amazon (Global)

@bpb_online #PythonForDevOps #DevOps #Python #Automation #CI_CD #CloudAutomation #InfrastructureAsCode #MLOps #Monitoring #PythonBooks #DevOpsTools #LearnDevOps #BPBPublications

Image description