Building a Multi-Technology Python Menu-Based Program: Integrating AWS, Docker, Ansible, and Linux

Kaushik Denge
6 min readJul 29, 2023

--

Introduction

In today’s rapidly evolving technology landscape, developers often find themselves working with multiple technologies, cloud services, and tools to create efficient and powerful applications. In this blog, we will explore a Python menu-based program that integrates various technologies such as AWS, Docker, Ansible, and Linux, providing a streamlined approach to perform essential operations within these technologies. We will take a closer look at the program’s functionality and how it leverages each technology to execute specific tasks.

The Python Tech Menu Program

Overview

The Python Tech Menu program is designed to provide users with a user-friendly interface to interact with different technologies and perform various operations. The menu-driven structure makes it easy for users to choose the technology they want to work with and then select the desired operation within that technology.

Getting Started

Before running the program, ensure that you have the following prerequisites installed on your system:

  • Python 3.x
  • AWS CLI (for AWS operations)
  • Docker (for Docker operations)
  • Ansible (for Ansible operations)

Program Structure

The program consists of several functions, each catering to a specific technology and its corresponding operations. Let’s briefly go through each of these functions:

  1. display_welcome_text(): Displays a welcome message at the beginning of the program, creating an eye-catching ASCII art using the pyfiglet library.
  2. display_menu(): Presents the main menu to the user, allowing them to choose a technology to work with.
  3. aws_operations(): Contains functions for performing AWS-related operations, such as listing instances, creating instances, stopping instances, and terminating instances.
  4. docker_operations(): Contains functions for Docker-related operations, including listing containers, running containers, stopping containers, and removing containers.
  5. nsible_operations(): Placeholder function for Ansible operations (not implemented in the provided code).
  6. linux_operations(): Contains Linux-related operations, such as checking system information, listing files in a directory, creating directories, and removing directories.

How it Works

The Python Tech Menu program runs in a loop, allowing the user to choose a technology from the main menu. Depending on the selected technology, the user can then choose from a list of operations within that technology.

For instance, if the user selects AWS Operations, they can perform actions like listing AWS instances, creating instances, stopping instances, or terminating instances. Similarly, for Docker Operations, the user can list Docker containers, run containers, stop containers, or remove containers.

The program utilizes the subprocess module to execute shell commands related to AWS, Docker, and Linux. For AWS operations, the program calls the AWS CLI commands to interact with AWS services. Similarly, for Docker operations, it invokes Docker commands to manage containers.

Detailed Description of Options and Technologies in the Python Tech Menu Program

In the Python Tech Menu program, users can interact with various technologies through a user-friendly menu-driven interface. Let’s explore each option and the technologies they represent in detail:

1. AWS Operations

The AWS Operations option allows users to interact with Amazon Web Services (AWS) through the AWS Command Line Interface (CLI). This technology enables users to access and manage a wide range of AWS services. The following operations are available under this option:

1.1 List AWS Instances

This operation lists all the EC2 instances running in the AWS account. EC2 (Elastic Compute Cloud) provides scalable virtual servers in the cloud.

1.2 Create an AWS Instance

With this operation, users can create a new EC2 instance. They need to provide details such as the instance type, AMI ID (Amazon Machine Image), and key name (SSH key pair).

1.3 Stop an AWS Instance

This operation allows users to stop a specific EC2 instance based on its instance ID. Stopping an instance puts it in a stopped state, and users can start it again later.

1.4 Terminate an AWS Instance

This operation permanently terminates an EC2 instance based on its instance ID. Terminating an instance removes it from the AWS account.

2. Docker Operations

The Docker Operations option enables users to work with Docker containers, which are lightweight and portable environments for running applications. The following operations are available under this option:

2.1 List Docker Containers

This operation lists all the Docker containers currently running on the system. Containers are instances of Docker images that execute applications in isolated environments.

2.2 Run a Docker Container

Users can run a Docker container using this operation. They need to provide the container name and the image name (the image from which the container is created).

2.3 Stop a Docker Container

This operation stops a specific Docker container based on its container name. Stopping a container halts its execution.

2.4 Remove a Docker Container

This operation removes a Docker container from the system based on its container name. Removing a container frees up system resources.

3. Ansible Operations

The Ansible Operations option in the Python Tech Menu program offers a set of capabilities to interact with Ansible, a powerful automation tool used for configuration management, application deployment, and task automation on remote hosts:

3.1 Run Ansible Playbook

An Ansible playbook is a YAML file that defines a set of tasks and configurations to be applied to remote hosts. With this operation, users can execute an Ansible playbook to orchestrate complex tasks across multiple systems. Playbooks can be tailored to install software, configure services, manage users, and perform various administrative tasks.

3.2 Install a Package on Remote Host

This operation allows users to install software packages on remote hosts using Ansible. Ansible’s module system provides pre-defined modules for package management on different operating systems. The package installation task can be executed on multiple hosts simultaneously, ensuring consistency across the infrastructure.

3.3 Execute a Command on Remote Host

The ability to execute commands on remote hosts is a fundamental feature of Ansible. With this operation, users can run arbitrary commands or scripts on one or multiple remote hosts, enabling various system administration tasks.

4. Linux Operations

The Linux Operations option enables users to perform basic operations on a Linux system. These operations are executed through shell commands. The following operations are available under this option:

4.1 Check System Information

This operation retrieves system information, such as the Linux kernel version and system architecture.

4.2 List Files in a Directory

Users can list files in a specified directory using this operation. It provides an overview of the files present in the given directory.

4.3 Create a Directory

This operation allows users to create a new directory at the specified path.

4.4 Remove a Directory

Users can remove a directory and its contents using this operation.

Conclusion

The Python Tech Menu program showcases the potential of Python as a versatile language for integrating various technologies seamlessly. By bringing together AWS, Docker, Ansible, and Linux operations under one user-friendly menu, developers can improve productivity and streamline their workflow.

NOTE: In the future, I will improve and add more features to the code.

Thank you.

--

--

No responses yet