Sign inSign up free

1458. Build an Ops Toolkit, Stage 2: Layered Configuration

medium 20 XP ~15 minHands-on lab

This is stage 2 of the opskit project. You keep working in ~/opskit: your code from stage 1 is already there, and it's saved as you work. Starting here without the earlier stages? A working version of them was put in for you. Run the tool from ~/opskit with python3 -m opskit ....

Task

Add a global option --config FILE (it comes before the command) and the command config:

  • opskit config show prints the configuration as JSON (indent=2, sorted keys). It's built in layers:
    1. defaults: threshold 90, services [], webhook_url null, log_file "/var/log/nginx/access.log";
    2. the config file, if there is one: --config FILE, or else ~/.config/opskit/config.json; its keys replace the defaults (extra keys are kept);
    3. the environment: OPSKIT_THRESHOLD (a whole number) replaces threshold, OPSKIT_WEBHOOK replaces webhook_url.
  • opskit config get KEY prints one value: strings as they are, anything else as JSON.
  • A missing --config file, invalid JSON, a non-number OPSKIT_THRESHOLD or an unknown key: a one-line error on stderr and exit 2, never a traceback.

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

Project: Build an Ops Toolkit in Python · stage 2 of 8

Create a free account to keep your code between stages.

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.