Network Automation Cookbook
eBook - ePub

Network Automation Cookbook

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

Karim Okasha

Share book
  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

Karim Okasha

Book details
Book preview
Table of contents
Citations

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

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
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.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
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.
Do you support text-to-speech?
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.
Is Network Automation Cookbook an online PDF/ePUB?
Yes, you can access Network Automation Cookbook by Karim Okasha in PDF and/or ePUB format, as well as other popular books in Ciencia de la computación & Programación en Python. We have over one million books available in our catalogue for you to explore.

Information

Year
2020
ISBN
9781789951875

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