Network Automation Cookbook
eBook - ePub

Network Automation Cookbook

Proven and actionable recipes to automate and manage network devices using Ansible

  1. 482 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Network Automation Cookbook

Proven and actionable recipes to automate and manage network devices using Ansible

About this book

Take your network automation skills to the next level with practical recipes on managing network devices from a variety of vendors like Cisco, Juniper, and Arista

Key Features

  • Use Ansible to automate network infrastructure with the help of step-by-step instructions
  • Implement network automation best practices to save cost, avoid critical errors, and reduce downtime
  • Deliver a robust automation framework by integrating Ansible with NAPALM, NetBox, and Batfish

Book Description

Network Automation Cookbook is designed to help system administrators, network engineers, and infrastructure automation engineers to centrally manage switches, routers, and other devices in their organization's network. This book will help you gain hands-on experience in automating enterprise networks and take you through core network automation techniques using the latest version of Ansible and Python.

With the help of practical recipes, you'll learn how to build a network infrastructure that can be easily managed and updated as it scales through a large number of devices. You'll also cover topics related to security automation and get to grips with essential techniques to maintain network robustness. As you make progress, the book will show you how to automate networks on public cloud providers such as AWS, Google Cloud Platform, and Azure. Finally, you will get up and running with Ansible 2.9 and discover troubleshooting techniques and network automation best practices.

By the end of this book, you'll be able to use Ansible to automate modern network devices and integrate third-party tools such as NAPALM, NetBox, and Batfish easily to build robust network automation solutions.

What you will learn

  • Understand the various components of Ansible
  • Automate network resources in AWS, GCP, and Azure cloud solutions
  • Use IaC concepts to design and build network solutions
  • Automate network devices such as Cisco, Juniper, Arista, and F5
  • Use NetBox to build network inventory and integrate it with Ansible
  • Validate networks using Ansible and Batfish

Who this book is for

This Ansible network automation book is for network and DevOps engineers interested in automating complex network tasks. Prior understanding of networking and basic Linux knowledge is required.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Network Automation Cookbook by Karim Okasha in PDF and/or ePUB format, as well as other popular books in Informatica & Programmazione in Python. We have over one million books available in our catalogue for you to explore.

Information

Automating Juniper Devices in the Service Providers Using Ansible

In this chapter, we will outline how to automate Juniper devices running the Junos OS software in a typical service provider (SP) environment. We will explore how to interact with Juniper devices using Ansible, and how to provision different services and protocols on Juniper devices using various Ansible modules. We will base our illustration on the following sample network diagram of a basic SP network:
The following table outlines the devices in our sample topology and their respective management Internet Protocols (IPs):
Device
Role
Vendor
Management (MGMT) Port
MGMT IP
mxp01
P Router
Juniper vMX 14.1
fxp0
172.20.1.2
mxp02
P Router
Juniper vMX 14.1
fxp0
172.20.1.3
mxpe01
PE Router
Juniper vMX 14.1
fxp0
172.20.1.4
mxpe02
PE Router
Juniper vMX 17.1
fxp0
172.20.1.5
The main recipes covered in this chapter are as follows:
  • Building the network inventory
  • Connecting and authenticating to Juniper devices
  • Enabling the Network Configuration Protocol (NETCONF) on Junos OS devices
  • Configuring generic system options on Juniper devices
  • Configuring interfaces on Juniper devices
  • Configuring Open Shortest Path First (OSPF) on Juniper devices
  • Configuring Multiprotocol Label Switching (MPLS) on Juniper devices
  • Configuring the Border Gate Protocol (BGP) on Juniper devices
  • Deploying configuration on Juniper devices
  • Configuring the Layer 3 virtual private network (L3VPN) service on Juniper devices
  • Gathering Juniper device facts using Ansible
  • Validating network reachability on Juniper devices
  • Retrieving operational data from Juniper devices
  • Validating the network state using PyEZ operational tables

Technical requirements

The code files for this chapter can be found here: https://github.com/PacktPublishing/Network-Automation-Cookbook/tree/master/ch3_junos.
The following are the software releases on which this chapter is based:
  • Ansible machine running CentOS 7
  • Ansible 2.9
  • Juniper Virtual MX (vMX) running Junos OS 14.1R8 and Junos OS 17.1R1 release
Check out the following video to see the Code in Action:
https://bit.ly/3ajF4Mp

Building the network inventory

In this recipe, we will outline how to build and structure the Ansible inventory to describe the sample SP network setup outlined previously. The Ansible inventory is a pivotal part in Ansible, as it defines and groups devices that should be managed by Ansible.

Getting ready

We create a new folder that will host all the files that we will create in this chapter. The new folder is named ch3_junos.

How to do it...

  1. Inside the new folder, ch3_junos, we create a hosts file with the following content:
$ cat hosts

[pe]
mxpe01 Ansible_host=172.20.1.3
mxpe02 Ansible_host=172.20.1.4

[p]
mxp01 Ansible_host=172.20.1.2
mxp02 Ansible_host=172.20.1.6

[junos]
mxpe[01:02]
mxp[01:02]

[core:children]
pe
p
  1. Create an Ansible.cfg file, as shown in the following code:
$ cat Ansible.cfg

[defaults]
inventory=hosts
retry_files_enabled=False
gathering=explicit
host_key_checking=False

How it works...

We build the Ansible inventory using the hosts file and we define multiple groups in order to group the different devices in our network infrastructure, as follows:
  • We create the PE group, which references all the MPLS Provider Edge (PE) nodes in our topology.
  • We create the P group, which references all the MPLS Provider (P) nodes in our topology.
  • We create the junos group, which references all the devices running Junos OS as the OS.
  • We create the core parent group, which references both the PE and P groups.
Finally, we create the Ansible.cfg file and configure it to point to our hosts file, to be used as the Ansible inventory file. We set the gathering to explicit in order to disable the setup module, which runs by default to discover facts for the managed hosts. Disabling the setup module is mandatory since the setup module will fail when run against network devices.
We can validate that our Ansible inventory is structured and written correctly by typing the following command:
$ Ansible-inventory --list

"all": {
"children": [
"core",
"junos",
"ungrouped"
]
},
"core": {
"children": [
"p",
"pe"
]
},
"junos": {
"hosts": [
"mxp01",
"mxp02",
"mxpe01",
"mxpe02"
]
},
"p": {
"hosts": [
"mxp01",
"mxp02"
]
},
"pe": {
"hosts": [
"mxpe01",
"mxpe02"
]
}

Connecting and authenticating to J...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. About Packt
  4. Contributors
  5. Preface
  6. Building Blocks of Ansible
  7. Managing Cisco IOS Devices Using Ansible
  8. Automating Juniper Devices in the Service Providers Using Ansible
  9. Building Data Center Networks with Arista and Ansible
  10. Automating Application Delivery with F5 LTM and Ansible
  11. Administering a Multi-Vendor Network with NAPALM and Ansible
  12. Deploying and Operating AWS Networking Resources with Ansible
  13. Deploying and Operating Azure Networking Resources with Ansible
  14. Deploying and Operating GCP Networking Resources with Ansible
  15. Network Validation with Batfish and Ansible
  16. Building a Network Inventory with Ansible and NetBox
  17. Simplifying Automation with AWX and Ansible
  18. Advanced Techniques and Best Practices for Ansible
  19. Other Books You May Enjoy