Skip to main content

Command Palette

Search for a command to run...

Day 15 : Python Libraries for DevOps

Updated
2 min read

Reading JSON and YAML in Python

  • As a DevOps Engineer you should be able to parse files, be it txt, json, yaml, etc.

  • You should know what all libraries one should use in Pythonfor DevOps.

  • Python has numerous libraries like os, sys, json, yaml etc that a DevOps Engineer uses in day to day tasks.

Task 1: Create a Dictionary in Python and write it to a json File.

  1. Read a json file services.json kept in this folder and print the service names of every cloud service provider.

services.json :

{
  "services": {
    "debug": "on",
    "aws": {
      "name": "EC2",
      "type": "pay per hour",
      "instances": 500,
      "count": 500
    },
    "azure": {
      "name": "VM",
      "type": "pay per hour",
      "instances": 500,
      "count": 500
    },
    "gcp": {
      "name": "Compute Engine",
      "type": "pay per hour",
      "instances": 500,
      "count": 500
    }
  }
}

  1. Read YAML file using python, file services.yaml and read the contents to convert yaml to json

services.yaml :

---
services:
  debug: 'on'
  aws:
    name: EC2
    type: pay per hour
    instances: 500
    count: 500
  azure:
    name: VM
    type: pay per hour
    instances: 500
    count: 500
  gcp:
    name: Compute Engine
    type: pay per hour
    instances: 500
    count: 500

This was it for day 15. If you have any suggestion/questions please comment below.

Looking forward to next challenge.

Happy coding.

More from this blog

Ajay Patel

116 posts