ebook img

Practical Network Automation: A beginner’s guide to automating and optimizing networks using Python, Ansible, and more PDF

220 Pages·2018·14.226 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Practical Network Automation: A beginner’s guide to automating and optimizing networks using Python, Ansible, and more

Practical Network Automation Second Edition A beginner's guide to automating and optimizing networks using Python, Ansible, and more Abhishek Ratan BIRMINGHAM - MUMBAI Practical Network Automation Second Edition 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: Amey Varangaonkar Acquisition Editor: Heramb Bhavsar Content Development Editor: Abhijit Sreedharan Technical Editor: Swathy Mohan Copy Editor: Safis Editing Project Coordinator: Jagdish Prabhu Proofreader: Safis Editing Indexer: Rekha Nair Graphics: Tom Scaria Production Coordinator: Jyoti Chauhan First published: November 2017 Second edition: December 2018 Production reference: 1221218 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78995-565-1 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 Packt.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.packt.com and, as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.packt.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 Abhishek Ratan has around 16 years of technical experience in networking, automation, and various ITIL processes, and has worked in a number of roles in different organizations. As a network engineer, security engineer, automation engineer, TAC engineer, tech lead, and content writer, he has gained a wealth of experience in his career. He also has a keen interest in strategy game playing and, when he is not working on technical stuff, he is busy spending time on his strategy games. He is currently leading the automation and monitoring team, learning, and expanding his automation and Artificial Intelligence skills in the ServiceNow. His previous experience includes working for companies such as Microsoft, Symantec, and Navisite. I would like to thank the contribution of Harish Kulasekaran in web framework and Ops API and Abhishek Gupta for Alexa Integration. About the reviewer Dilip Reddy Guda has acquired expertise in the unified communications domain, along with IP network switching and routing. He has worked on session border controllers, such as CUBE, SIP Server, SIP proxies, CUCM, and CISCO gateways, including SRST, BE4K, CME, and UCCE. He has expertise in SIP protocol, H323, and TDM technologies, along with experience in C++ based application development for Huawei's NGIN solution, and TCL programming. He also has expertise in Python programming involving network device automation, and DevOps framework development. Skilled in RESTful API development, he is a network programming engineer with experience of Python programming, IP networking domains, and REST API framework development for network automation. 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 1 Chapter 1: Fundamental Concepts of Network Automation 5 Technical requirements 5 A readable script 6 Basic programs 7 Validating an IPv4 address 7 Making the right choice 9 Hiding credentials 10 Accessing APIs 11 Using regular expressions (regex) 12 Handling files 14 Making a decision (Python or PowerShell) 15 API access 16 Interacting with local machines 17 Introduction to code check-in and its importance 18 Git installation and initialization 18 Code check-in 22 Sample use cases 24 First use case 25 Second use case 29 Summary 34 Questions 34 Chapter 2: Python Automation for Network Engineers 35 Technical requirements 35 Interacting with network devices 36 Network device configuration using template 45 Multithreading 52 Use cases 55 Using regular expressions (regex) 56 Creating loopback interface 58 Dynamic configuration updates 62 Summary 64 Questions 65 Chapter 3: Ansible and Network Templatizations 66 Technical requirements 67 Ansible and network templates 67 Introduction to ad hoc commands 68 Table of Contents Ansible playbooks 72 Playbook examples 73 Ping to a particular IP from all routers 73 Section 1 – defining the scope of script 74 Section 2 – defining what to execute (define the task) 74 Ping to multiple IPs from all routers 76 Section 1 – basic declarations 78 Section 2 – declaring variables 79 Section 3 – executing the task 79 Section 4 – validations 80 Network templates 82 Step 1 – identifying the number of users the device is going to serve 82 Step 2 – identifying the right configuration based upon the SKU 82 Step 3 – identifying the role of the device 83 Python integration 85 Chef and Puppet 89 Chef 89 Step 1 – creating the recipe 92 Step 2 – uploading the recipe 92 Step 3 – adding the recipe to the run-list 92 Step 4 – running the recipe 92 Puppet 93 Chef/Puppet/Ansible comparison 94 Summary 95 Questions 95 Chapter 4: Using Artificial Intelligence in Operations 96 Technical requirements 96 AI in IT operations 97 Key pillars in AIOps 97 Data source 97 Structured data 98 Non-structured data 98 Data collector 98 Data analysis 100 Machine Learning (ML) 102 Example of linear regression 104 Intelligent remediation 113 Application and use cases 117 Summary 123 Questions 124 Chapter 5: Web Framework for Automation Triggers 125 Technical requirements 125 Web framework 126 Falcon 128 Encoding and decoding 132 Calling the web framework 138 [ ii ] Table of Contents Sample use case 142 Summary 152 Questions 152 Chapter 6: Continual Integration 153 Technical requirements 153 Remediation using intelligent triggers 154 Step 1 – ensuring Splunk is configured to receive the data 155 Step 2 – validating the data (sample data) 158 Step 3 – writing script 159 Standardizing configurations on scale 174 Chatbot interactions 180 Use cases 194 Interacting with SolarWinds 195 Configuring Open Shortest Path First (OSPF) through Python 196 Autonomous System Number (ASN) in BGP 198 Validating the IPv4 and IPv6 addresses 199 Summary 200 Questions 201 Assessment 202 Other Books You May Enjoy 206 Index 209 [ iii ] Preface Network automation is the use of IT controls to supervise and carry out everyday network management functions. It plays a key role in network virtualization technologies and network functions. The book starts by providing an introduction to network automation, and its applications, which include integrating DevOps tools to automate the network efficiently. It then guides you through different network automation tasks and covers various data digging and performing tasks such as ensuring golden state configurations using templates, interface parsing. This book also focuses on Intelligent Operations using Aritifical Intelligence and troubleshooting using chatbots and voice commands. The book then moves on to the use of Python and the management of SSH keys for machine-to-machine (M2M) communication, all followed by practical use cases. The book also covers the importance of Ansible for network automation, including best practices in automation; ways to test automated networks using tools such as Puppet, SaltStack, and Chef; and other important techniques. Through practical use cases and examples, this book will acquaint you with the various aspects of network automation. It will give you the solid foundation you need to automate your own network without any hassle. Who this book is for If you are a network engineer or a DevOps professional looking for an extensive guide to help you automate and manage your network efficiently, then this book is for you. No prior experience with network automation is required to get started. However, you will need some exposure to Python programming to get the most out of this book. What this book covers Chapter 1, Fundamental Concepts of Network Automation, introduces you to how to get started with automation. This will also help you learn and understand the various important aspects of network automation. Chapter 2, Python Automation for Network Engineers, walks you through the methods and samples of how to get data and parse through the use of regexes. We will also learn about a number of advanced topics, such as writing Python scripts for network automation. With the help of a use case, readers will be able to automate their network using Python.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.