Interview Prep/Python for DevOps/Automation scripting & CLI design

You need a script that ops engineers run from laptops and that CI runs nightly. How do you design its interface?

IntermediateScenarioAutomation scripting & CLI design
Answer

Situation read → Two audiences: humans (readable output, prompts) and machines (stable output, exit codes, no prompts).

What I'd do →

  1. click CLI with subcommands, every option settable via env var (envvar=).
  2. --format table|json; default to table when sys.stdout.isatty() and JSON otherwise.
  3. Logs on stderr, data on stdout; -v/-vv for verbosity.
  4. Documented exit codes: 0 clean, 1 error, 2 findings.
  5. No interactive prompt when stdin is not a TTY; destructive actions require --yes.
  6. Package it with a console script so both laptop (pipx install) and CI (docker run) use the same entry point.

Why → One tool, two consumers, no forked logic.

Interview tip → "stdout is an API" is the phrase interviewers like to hear.

All Python for DevOps questions Roadmap: Python for automation

More on Automation scripting & CLI design