Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Network Automation Cookbook
Network Automation Cookbook

Network Automation Cookbook: Proven and actionable recipes to automate and manage network devices using Ansible

eBook
£26.99
Paperback
£32.99
Subscription
Free Trial
Renews at £9.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Network Automation Cookbook

Managing Cisco IOS Devices Using Ansible

In this chapter, we will outline how to automate Cisco IOS-based devices using Ansible. We will explore the different modules available in Ansible to automate configuration and collect network information from Cisco IOS devices. This chapter will be based on the following sample network diagram, and we will walk through how we can implement this network design using Ansible:

The following table outlines the management IP addresses on the Cisco nodes, which Ansible will use to connect to the devices:

Device

Role

Vendor

MGMT Port

MGMT IP

access01

Access switch

Cisco IOS 15.1

Ethernet0/0

172.20.1.18

access02

Access switch

Cisco IOS 15.1

Ethernet0/0

172.20.1.19

core01

Core switch

Cisco IOS 15.1

Ethernet0/0

172.20.1.20

core02

Core switch

Cisco IOS 15.1

Ethernet0/0

172.20.1.21

...

Technical requirements

Building an Ansible network inventory

In this recipe, we will outline how to build and structure the Ansible inventory to describe the network setup outlined in the previous section.

Getting ready

Make sure that Ansible is already installed on the control machine.

How to do it...

  1. Create a new directory with the following name: ch2_ios.
  2. Inside this new folder, create the hosts file with the following content:
$ cat hosts
[access]
access01 Ansible_host=172.20.1.18
access02 Ansible_host=172.20.1.19

[core]
core01 Ansible_host=172.20.1.20
core02 Ansible_host=172.20.1...

Connecting to Cisco IOS devices

In this recipe, we will outline how to connect to Cisco IOS devices from Ansible via SSH in order to start managing devices from Ansible.

Getting ready

In order to follow along with this recipe, an Ansible inventory file should be constructed as per the previous recipe. IP reachability between the Ansible control machine and all the devices in the network must be configured.

How to do it...

  1. Inside the ch2_ios directory, create the groups_vars folder.
  2. Inside the group_vars folder, create the network.yml file with the following...

Configuring basic system information

In this recipe, we will outline how we can configure basic system parameters on Cisco IOS devices, such as setting the hostname, DNS server, and NTP servers. Following the network setup that we outlined at the start of this chapter, we will configure the following information on all the Cisco IOS devices:

  • DNS servers 172.20.1.250 and 172.20.1.251
  • NTP server 172.20.1.17

Getting ready

An Ansible inventory file must be present, as well as the configuration for Ansible to connect to the Cisco IOS devices via SSH.

How to do it...

  1. To the...

Configuring interfaces on IOS devices

In this recipe, we will outline how to configure the basic interface properties on Cisco IOS-based devices, such as setting the interface description, the interface maximum transmission unit (MTU), and enabling interfaces. We will configure all the links within our topology as having a link MTU of 1,500 and to be fully duplex.

Getting ready

To follow along with this recipe, an Ansible inventory is assumed to be already set up, as is IP reachability between the Ansible control node with the Cisco devices in place.

How to do it...

  1. In...

Configuring L2 VLANs on IOS devices

In this recipe, we will outline how to configure L2 VLANs on Cisco IOS devices, as per the network topology discussed in the introduction to this chapter. We will outline how to declare VLANs as Ansible variables, and how to use suitable Ansible modules to provision these VLANs on the network.

Getting ready

We will be building on the previous recipes discussed in this chapter to continue to configure the L2 VLANs on all the LAN devices within our sample topology.

How to do it...

  1. Update the group_vars/lan.yml file with the VLAN definition...

Configuring trunk and access interfaces

In this recipe, we will show how to configure access and trunk interfaces on Cisco IOS-based devices, and how to map interfaces to an access VLAN, as well as how to allow specific VLANs on the trunks.

Getting ready 

Following our sample topology, we will configure the interfaces on the devices. As shown in this table, we are only showing the VLANs for access01 and core01— the other devices are exact replicas:

Device

Interface

Mode

VLANs

Core01

Ethernet0/1

Trunk

10,20,100

Core01

Ethernet0/2

Trunk

10,20,100

Core01

Ethernet0/3

Trunk

10,20,100,200

Access01

Ethernet0/1

Trunk

10,20,100

Access01

Ethernet0/2

Trunk

10,20...

Configuring interface IP addresses

In this recipe, we will explore how to configure the interface IP address on Cisco IOS devices. We will use the sample topology to configure the VLAN interfaces on both the core switches. We will outline how to configure VRRP between the core switches for all the VLAN interfaces. We will configure the following IP addresses:

Interface

Prefix

VRRP IP address

VLAN10

10.1.10.0/24

10.1.10.254

VLAN20

10.1.20.0/24

10.1.20.254

VLAN100

10.1.100.0/24

10.1.100.254

Getting ready

This recipe assumes that the interface and VLANs are configured as per the previous recipes in this chapter.

...

Configuring OSPF on IOS devices

In this recipe, we will outline how to configure OSPF on Cisco IOS devices with Ansible. Using our sample network topology, we will set up OSPF between core switches and WAN routers, as well as advertising the SVI interface via OSPF.

Getting ready

This recipe assumes that all the interfaces are already configured with the correct IP addresses and are following the same procedures outlined in previous recipes.

How to do it...

  1. Update the group_vars/core.yml file with the following data to define core links between core switches and WAN routers...

Collecting IOS device facts

In this recipe, we will outline how to collect device facts from Cisco devices with Ansible. This information includes the serial number, IOS version, and all the interfaces on the devices. Ansible executes several commands on managed IOS devices in order to collect this information.

Getting ready

The Ansible controller must have IP connectivity with the managed network devices, and SSH must be enabled on the IOS devices.

How to do it...

  1. Create a new playbook called pb_collect_facts.yml in the same ch2_ios folder with the following information...

Validating network reachability on IOS devices

In this recipe, we will outline how to validate network reachability via ping using Ansible. ICMP allows us to validate proper forwarding across our network. Using Ansible to perform this task provides us with a robust tool to validate proper traffic forwarding, since we can perform this task from each node simultaneously and collect all the results for further inspection.

Getting ready

This recipe is built based on the network setup that was outlined in the chapter introduction, and I am assuming that the network has already been built in accordance with all the previous recipes in this chapter.

...

Retrieving operational data from IOS devices

In this recipe, we will outline how to execute operational commands on IOS devices and store these outputs to text files for further processing. This allows us to capture any operational commands from IOS devices during pre- or post-validation after we perform any deployment so that we can compare the results.

Getting ready

In order to follow along with this recipe, an Ansible inventory file should be in place and the network should already be set up as per the previous recipes.

How to do it...

  1. Create a new playbook called...

Validating network states with pyATS and Ansible

In this recipe, we will outline how to use Ansible and the Cisco pyATS Python library to execute and parse operational commands on Cisco devices. Using these parsed commands, we can validate various aspects of the network.

Getting ready

This recipe assumes that the network has already been built and configured as outlined in all the previous recipes.

How to do it...

  1. Install the Python libraries needed for pyATS:
$ sudo pip3 install pyats genie
  1. Create the roles directory and then create the requirements.yml file with...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • 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

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.

Who is this book 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.

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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 17, 2020
Length: 482 pages
Edition : 1st
Language : English
ISBN-13 : 9781789951875
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 17, 2020
Length: 482 pages
Edition : 1st
Language : English
ISBN-13 : 9781789951875
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
£9.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 6,500+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
£99.99 billed annually
Feature tick icon Unlimited access to Packt's library of 6,500+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts
£139.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 6,500+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total £ 148.97
Mastering Linux Security and Hardening
£44.99
Network Automation Cookbook
£32.99
Mastering Python Networking
£70.99
Total £ 148.97 Stars icon
Banner background image

Table of Contents

14 Chapters
Building Blocks of Ansible Chevron down icon Chevron up icon
Managing Cisco IOS Devices Using Ansible Chevron down icon Chevron up icon
Automating Juniper Devices in the Service Providers Using Ansible Chevron down icon Chevron up icon
Building Data Center Networks with Arista and Ansible Chevron down icon Chevron up icon
Automating Application Delivery with F5 LTM and Ansible Chevron down icon Chevron up icon
Administering a Multi-Vendor Network with NAPALM and Ansible Chevron down icon Chevron up icon
Deploying and Operating AWS Networking Resources with Ansible Chevron down icon Chevron up icon
Deploying and Operating Azure Networking Resources with Ansible Chevron down icon Chevron up icon
Deploying and Operating GCP Networking Resources with Ansible Chevron down icon Chevron up icon
Network Validation with Batfish and Ansible Chevron down icon Chevron up icon
Building a Network Inventory with Ansible and NetBox Chevron down icon Chevron up icon
Simplifying Automation with AWX and Ansible Chevron down icon Chevron up icon
Advanced Techniques and Best Practices for Ansible Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(4 Ratings)
5 star 50%
4 star 0%
3 star 25%
2 star 25%
1 star 0%
Tristan Ziemann Mar 01, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I really like how he covers the top 3 for networking vendors and cloud vendors. I work with Arista and I’ll vouch these examples are good. I work with the other platforms too. Anyways, i encourage you to read this book.
Amazon Verified review Amazon
Bobby R. Apr 27, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Coming from an older version of ansible, this book helped explain what's new with Ansible. Also it gives you enough information for you to customize playbooks for your environment. Will find myself flipping through the pages looking for ways to perform tasks, and will not let you down on knowledge. Make sure you download the files for this book, will help speed up your knowledge!
Amazon Verified review Amazon
Kirito Yuuki Aug 24, 2023
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
I thought it was about computers in cars, but even with that said. It's still an interesting read and to know.😅😎
Amazon Verified review Amazon
Elizabete Jesus Aug 23, 2022
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
You definitely need to know some ansible before reading this book as the concepts are not well explained.Also, a lot of typos and errors in the sample code. You'll have to find your way thru it.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.