Hands-On Enterprise Automation with Python
Automate common administrative and security tasks
with Python
Bassem Aly
BIRMINGHAM - MUMBAI
Hands-On Enterprise Automation with Python
Copyright 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Vijin Boricha
Acquisition Editor: Rohit Rajkumar
Content Development Editor: Ron Kurien
Technical Editor: Manish D Shanbhag
Copy Editor: Safis Editing
Project Coordinator: Judie Jose
Proofreader: Safis Editing
Indexer: Pratik Shirodkar
Graphics: Tom Scaria
Production Coordinator: Aparna Bhagat
First published: June 2018
Production reference: 1270618
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78899-851-2
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
Bassem Aly is an experienced SDN/NFV solution consultant at Juniper Networks and has been working in the telco industry for the last 9 years. He has focused on designing and implementing next-generation solutions by leveraging different automation and DevOps frameworks. Also, he has extensive experience of architecting and deploying telco applications over OpenStack. He also conducts corporate training on network automation and network programmability using Python and Ansible.
I would like to thank my amazing wife, Sarah, and my fantastic daughter, Mariam. They've sacrificed many nights and meals for this dream. I hope Mariam will read this book one day and understand why I spent so much time on the computer instead of chasing. Thanks to my parents for their encouragement, which made me who I am today. Finally, thanks to my mentor, Ashraf Albasti, who has helped me in countless ways in my career.
About the reviewer
JereJulian is a senior network automation engineer with nearly two decades of automation experience currently focused on workflow simplification through automation. The past few years have found him on the speaker circuit at DevOps Days and Interop ITX, as well as regularly contributing to network computing. He lives in NC with his wife and two boys and fights fire as a community volunteer as opposed to the data center. He can be contacted on Twitter at @julianje.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Table of Contents
Preface
The book 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 the cloud infrastructure with Python. In the concluding chapters, you will cover Python-based offensive security tools and learn 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.
You can visit the author's blog at the following link: https://basimaly.wordpress.com/.
Who this book is for
Hands-On Enterprise Automationwith Python is for system administrators and DevOps engineers who are looking for an alternative to major automation frameworks such as Puppet and Chef. Basic programming knowledge with Python and Linux shell scripting is necessary.
What this book covers
, Setting Up Python Environment, explores how to download and install the Python interpreter along with the Python Integrated Development Environment, called JetBrains PyCharm. The IDE provides you with smart autocompletion, intelligent code analysis, powerful refactoring and integrates with Git, virtualenv, Vagrant, and Docker. This will help you to write professional and robust Python code.
, Common Libraries Used in Automation, covers the Python libraries that are available today and that are used for automation. We will categorize them based on their usage (system, network, and cloud) and provide a simple introduction. As you progress through the book, you will find yourself deep diving into each of them and understanding their usage.
, Setting up Your Network Lab Environment, discusses the merits of network automation and how network operators use it today to automate the current devices. We will explore popular libraries that are used today to automate network nodes from Cisco, Juniper, and Arista. This chapter covers how to build a networking lab to apply the Python script on. We will use an open source network emulation tool called EVE-NG.