InterviewStack.io LogoInterviewStack.io

Python Scripting for Infrastructure Automation Questions

Applied Python skills for building reusable, production grade automation for infrastructure and operations. Topics include designing modular automation code and libraries, using relevant third party libraries for systems administration and remote management, invoking and controlling subprocesses, interacting with application programming interfaces and cloud platform endpoints, robust error handling and structured logging, automated testing of scripts and modules, packaging and distributing tools for reuse, secure credential management, integration with configuration management and orchestration tooling, and designing multi step workflows and idempotent operations. Candidates should demonstrate experience with writing maintainable automation, reasoning about failure modes, and selecting appropriate abstractions and libraries for operational tasks.

HardTechnical
0 practiced
Legacy repositories contain many Python scripts invoking subprocesses without timeouts, retries, or proper error checks. Describe how to implement a static analysis tool (using AST) to scan repositories and flag calls to subprocess.Popen/call/run that lack timeout arguments or a try/except wrapper. Provide pseudocode or a small detection rule using Python's ast module and explain how to integrate this check into CI as a blocking lint step.
MediumTechnical
0 practiced
Implement a Python helper 'run_cli(cmd: List[str], timeout: int, log_file: str)' that runs an external CLI safely: it should enforce a timeout, stream stdout and stderr to a rotating log file, return the exit code, and ensure no zombie processes remain if the parent crashes or is killed. Show key code and explain how you guarantee resource cleanup on termination.
MediumTechnical
0 practiced
Implement a Python function 'put_s3_object(bucket: str, key: str, content: bytes, metadata: dict = None)' using boto3 that writes an object only if the content or metadata changed. Ensure idempotency by comparing ETag or object checksum where possible, consider object versioning, and implement retries on throttling (HTTP 429/503). Show the core logic and how you handle conditional writes safely.
MediumTechnical
0 practiced
Write a Python script 'runbook-runner.py' that consumes a YAML runbook of steps like:
- name: create-db run: ./scripts/create_db.sh rollback: ./scripts/drop_db.sh
The runner must execute steps sequentially, support '--dry-run', support '--parallel' to run independent steps concurrently (assume the YAML indicates dependencies), and implement rollback behavior which executes rollback commands in reverse order if any step fails. Outline code structure, error handling, and how you would implement dependency-based parallelism and rollback ordering.
EasyTechnical
0 practiced
Implement a Python function 'http_get_with_retry(url: str, max_attempts: int = 5, timeout: int = 10)' that performs an HTTP GET using the 'requests' library and retries on transient network errors and 5xx responses. Use exponential backoff with jitter between retries, and ensure you do not retry on 4xx client errors that are permanent. If 'tenacity' is available you may outline how to use it; otherwise implement the retry loop yourself. Keep the function idempotent and allow caller to configure max_attempts and timeout.

Unlock Full Question Bank

Get access to hundreds of Python Scripting for Infrastructure Automation interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.