Quick Start¶
This guide walks through creating your first Cook configuration.
Your First Configuration¶
Create a file named server.py:
from cook import File, Package, Service
# Install nginx
Package("nginx")
# Configure nginx
File("/etc/nginx/nginx.conf",
content="""
events { worker_connections 1024; }
http {
server {
listen 80;
location / {
return 200 'Hello from Cook';
}
}
}
""",
mode=0o644)
# Ensure nginx is running
Service("nginx", running=True, enabled=True)
Preview Changes¶
See what Cook will do without making changes:
Output:
Planning resources...
[Package] nginx
Action: create
Changes:
type: None → nginx
[File] /etc/nginx/nginx.conf
Action: create
Changes:
content: None → <content>
mode: None → 0o644
[Service] nginx
Action: update
Changes:
running: False → True
enabled: False → True
Summary: 3 resources, 3 changes
Apply Configuration¶
Execute the changes:
Output:
Applying changes...
[Package] nginx: Installing
[File] /etc/nginx/nginx.conf: Creating
[Service] nginx: Starting and enabling
Complete: 3 resources applied successfully
Verify¶
Check that nginx is running:
Expected output:
Idempotency¶
Run apply again:
Output:
Cook detects that the system already matches the desired state.
Make Changes¶
Edit server.py to change the response:
File("/etc/nginx/nginx.conf",
content="""
events { worker_connections 1024; }
http {
server {
listen 80;
location / {
return 200 'Updated response';
}
}
}
""",
mode=0o644)
Plan and apply:
Cook updates only the changed file and reloads nginx.