Book Image

Hands-On Enterprise Automation with Python

By : Bassem Aly
Book Image

Hands-On Enterprise Automation with Python

By: Bassem Aly

Overview of this book

Hands-On Enterprise Automation with Python starts by covering the set up of a Python environment to perform automation tasks, as well as the modules, libraries, and tools you will be using. We’ll explore examples of network automation tasks using simple Python programs and Ansible. Next, we will walk you through automating administration tasks with Python Fabric, where you will learn to perform server configuration and administration, along with system administration tasks such as user management, database management, and process management. As you progress through this book, you’ll automate several testing services with Python scripts and perform automation tasks on virtual machines and cloud infrastructure with Python. In the concluding chapters, you will cover Python-based offensive security tools and learn how to automate your security tasks. By the end of this book, you will have mastered the skills of automating several system administration tasks with Python.
Table of Contents (20 chapters)

Using the Subprocess Module

Running and spawning a new system process can be useful to system administrators who want to automate specific operating system tasks or execute a few commands within their scripts. Python provides many libraries to call external system utilities, and it interacts with the data produced. The first library that was created is the OS module, which provides some useful tools to invoke external processes, such as os.system, os.spwan, and os.popen*. It lacks some essential functions, however, so Python developers have introduced a new library, subprocess, which can spawn new processes, send and receive from the processes, and handle error and return codes. Currently, the official Python documentation recommends the subprocess module for accessing system commands, and Python actually intends to replace the older modules with it.

The following topics will...