Day 96: Functions & Arguments in Python
Using Python Functions and Arguments in DevOps Automation

Today, I learned how to create functions in Python β the building blocks of reusable and modular scripts.
In DevOps, this helps break down complex tasks (like provisioning, deployments, log parsing) into clean, reusable components.
βοΈ What are Functions?
A function is a reusable block of code that performs a specific task.
def greet():
print("Hello DevOps World!")
greet()
β This helps avoid repetition and makes scripts easier to manage.
π₯ Functions with Arguments
Functions can take arguments to make them dynamic.
def deploy_app(server_name):
print(f"Deploying app to {server_name}")
deploy_app("web01")
β Useful when automating tasks for multiple servers or different environments.
π¦ Functions with Multiple / Lengthy Arguments
We can pass multiple arguments or use *args and **kwargs to handle variable-length arguments.
# Using *args (non-keyword arguments)
def configure_servers(*servers):
for s in servers:
print(f"Configuring {s}")
configure_servers("web01", "web02", "db01")
# Using **kwargs (keyword arguments)
def create_vm(**details):
for key, value in details.items():
print(f"{key} : {value}")
create_vm(name="devVM", region="us-east-1", size="t2.micro")
β
*args is useful for looping through a list of servers.
β
**kwargs is useful for passing key-value configuration like environment variables, tags, and metadata.
π‘ Key Takeaways
Functions help write clean, modular scripts.
Arguments make them dynamic and reusable.
*argsand**kwargsgive flexibility for automation tasks.
This is a crucial step in writing scalable DevOps automation scripts.




