Day 1. Network Automation

CCNA 200-301 Exam Topics

  • Explain how automation impacts network management

  • Describe characteristics of REST based APIs (CRUD, HTTP verbs, data encoding)

  • Recognize the capabilities of configuration management mechanisms Puppet, Chef, and Ansible

  • Interpret JSON encoded data

Key Topics

Today we review how network automation impacts network management. Specifically, we review the configuration management tools Puppet, Chef, and Ansible. These tools, as well as other network management tools, make use of Representational State Transfer application programming interfaces (REST APIs) and JavaScript Object Notation (JSON) data.

Data Formats

Data formats provide a way to store and exchange data in a structured format. These are some common data formats used in network automation and programmability:

  • JavaScript Object Notation (JSON)

  • Extensible Markup Language (XML)

  • YAML Ain’t Markup Language (YAML)

Table 1-1 compares the main purposes and common uses of these data formats.

Table 1-1 Data Format Comparison

Data Format

Origin/Definition

Central Purpose

Common Use

JSON

JavaScript (JS) language; RFC 8259

General data modeling and serialization

REST APIs

XML

World Wide Web Consortium (W3C.org)

Data-focused text markup, which allows data modeling

REST APIs, web pages

YAML

YAML.org

General data modeling

Ansible

Each data format has specific characteristics:

  • Syntax, which includes the types of brackets used, such as [ ], ( ), and { }, the use of whitespace, indentation, quotes, commas, and more.

  • How objects are represented, such as characters, strings, lists, and arrays.

  • How key/value pairs are represented. The key, which is usually on the left side, identifies or describes the data. The value on the right is the data itself and can be a character, a string, a number, a list, or another type of data.

The data format that is selected depends on the format used by the application, tool, or script involved. However, the CCNA exam focuses specifically on the interpretation of JSON data.

JSON Data Format

JSON is a human-readable data format used by applications for storing, transferring, and reading data. It is easy to parse and can be used with most modern programming languages, including Python.

Example 1-1 shows partial IOS output from the show interface GigabitEthernet0/0/0 command on a router.

Example 1-1 IOS Router Output

GigabitEthernet0/0/0 is up, line protocol is up (connected)
  Description: Wide Area Network
  Internet address is 172.16.0.2/24

Example 1-2 shows how this information can be represented in JSON format.

Example 1-2 JSON Output

{
    "ietf-interfaces:interface": {
         "name": "GigabitEthernet0/0/0",
         "description": "Wide Area Network",
         "enabled": true,
         "ietf-ip:ipv4": {
             "address": [
                 {
                     "ip": "172.16.0.2",
                     "netmask": "255.255.255.0"
                 }
             ]
          }
    }
}

JSON Syntax Rules

JSON data is a collection of key:value pairs that follow these rules:

  • Key:value pair: One key:value pair

  • Key: Text inside double quotes and before the colon that is used as the name that references a value

  • Value: The item after the colon that represents the value of the key, which can be

    • Text: Listed in double quotes

    • Numeric: Listed without quotes

    • Array: A list of values enclosed in square brackets [ ]

    • Object: One or more key:value pairs enclosed in braces { }

  • Multiple Pairs: When listing multiple key:value pairs, separate the pairs with a comma at the end of each pair (except the last one)

A list of IPv4 addresses might look as shown in Example 1-3. The key here is addresses. The value is an array. Inside the array, each item is a separate object, and those objects are separated by braces { }. The objects are two key:value pairs: an IPv4 address (ip) and a subnet mask (netmask) separated by a comma. The objects in the array are also separated by commas, with a comma following the closing brace for each object. After all the items in the array are defined, the array is closed with the right bracket.

Example 1-3 JSON List of IPv4 Addresses

{
  "addresses": [
    {
      "ip": "172.16.0.2",
      "netmask": "255.255.255.0"
    },
    {
      "ip": "172.16.0.3",
      "netmask": "255.255.255.0"
    },
    {
      "ip": "172.16.0.4",
      "netmask": "255.255.255.0"
    }
  ]
}

RESTful APIs

APIs exist to allow two programs to exchange data. Some APIs are for interprogram communications within a single operating system (OS). Other APIs are available to programs that run on other computers. These APIs must define the networking protocol. Many are based on REST.

REST is an architectural style for designing web service applications. A REST API is an API that works on top of the HTTP protocol. It defines a set of functions developers can use to perform requests and receive responses through HTTP, such as GET and POST. An API can be considered RESTful if it has the following features:

  • Client/server: The client handles the front end, and the server handles the back end. Either can be replaced independently of the other.

  • Stateless: No client data is stored on the server between requests. The session state is stored on the client.

  • Cacheable: Clients can cache responses to improve performance.

RESTful Implementation

A RESTful web service is a collection of resources with four defined aspects:

  • The data format supported by the web service, which is often JSON, XML, or YAML

  • The set of operations supported by the web service using HTTP methods

  • The API, which must be hypertext driven

  • The base uniform resource identifier (URI) for the web service, such as http://example.com/resources

RESTful APIs use common HTTP methods, including POST, GET, PUT, PATCH, and DELETE. As shown in Table 1-2, these methods correspond to RESTful operations: create, read, update, and delete (or CRUD).

Table 1-2 HTTP Methods and RESTful Operation

HTTP Method

RESTful Operation

POST

Create

GET

Read

PUT/PATCH

Update

DELETE

Delete

RESTful API Requests

A RESTful API is requested by using a URI, which is a string of characters that identifies a specific network resource. As shown in the Figure 1-1, a URI has two specializations:

  • Uniform resource name (URN): Identifies only the namespace of the resource without reference to the protocol.

  • Uniform resource locator (URL): Defines the network location of a specific resource on the network.

Figure 1-1 Structure of a URI

These are the parts of a URI, as shown in Figure 1-1:

  • Protocol/scheme: HTTPS or another protocol, such as FTP, SFTP, mailto, or NNTP

  • Hostname: In this case, www.example.com

  • Path and file name: In this case, /author/book.html

  • Fragment: In this case, #page155

A RESTful API request elicits a response from the API server. For example, the URI in Figure 1-2 is a properly formed GET request to the MapQuest API server for directions from San Jose to Monterey in JSON format.

Figure 1-2 RESTful API Request to the MapQuest API Server

These are the different parts of the API request:

  • API server: The URL for the server that answers REST requests.

  • Resources: Specifies the API that is being requested.

  • Query: Specifies the data format and information the client is requesting from the API service. Queries can include

    • Format: This is usually JSON but can be YAML or XML.

    • Key: The key is for authorization, if required.

    • Parameters: Parameters are used to send information pertaining to the request.

The beginning of the JSON payload delivered by the request in Figure 1-2 would look as shown in Example 1-4.

Example 1-4 JSON Payload Received from an API Request

{
  "route": {
    "hasTollRoad": false,
    "hasBridge": true,
    "boundingBox": {
      "lr": {
        "lng": -121.667061,
        "lat": 36.596809
      },
      "ul": {
        "lng": -121.897125,
        "lat": 37.335358
      }
    },
    "distance": 71.712,
    "hasTimedRestriction": false,
    "hasTunnel": false,
    "hasHighway": true,
    "computedWaypoints": [],
    "routeError": {
      "errorCode": -400,
      "message": ""
    },
(output omitted)

Configuration Management Tools

A company with one network engineer might be fine managing device configurations, especially if the configurations do not change often. The manual per-device configuration model makes great sense. With that model, the one network engineer can use the on-device startup-config as the intended ideal configuration, and he or she can make changes as needed. However, this method does not work as well for larger networks, with hundreds or even thousands of network devices and multiple network engineers. Larger networks typically make use of configuration management tools.

Configuration management tools provide different methods to define logic and processes that indicate what changes the tools should make, to which devices, and when. For each tool, engineers use a language of some kind to define the action steps. The language is often a language defined by the company offering the tool, but the tool’s language is generally much easier to learn than a programming language.

Configuration tools specified for the CCNA exam are Ansible, Puppet, and Chef.

Ansible

Ansible uses an agentless architecture to manage network devices. Agentless means that the network device does not need code. Ansible uses SSH or NETCONF to make changes and extract information. Ansible uses a push model, as shown in Figure 1-3.

Figure 1-3 Ansible Push Model

Ansible uses several text files, as shown in Figure 1-3:

  • Playbooks: Files with actions and logic about what Ansible should do

  • Inventory: Device hostnames along with information about each device, such as device roles, so Ansible can perform functions for subsets of the inventory

  • Templates: A device configuration with variables

  • Variables: A list of YAML variables that Ansible will substitute into templates

In Figure 1-3, the engineer builds all the necessary files (1). Then the engineer tells the Ansible control server to run a playbook (2), which then gets pushed to the device (3) or devices.

Puppet

Puppet typically uses an agent-based architecture for network device support. Some network devices enable Puppet support through an on-device agent. However, not every Cisco OS supports Puppet agents, and Puppet solves that problem using a proxy agent running on some external host (called agentless operation). The external agent then uses SSH to communicate with the network device, as shown in Figure 1-4.

Figure 1-4 Agent-Based or Agentless Operation for Puppet

Puppet uses a pull model to get a configuration to appear in the device, as shown in Figure 1-5.

Figure 1-5 Puppet Pull Model

Puppet uses several important text files with different components (refer to Figure 1-5):

  • Manifest: A human-readable text file that defines the desired configuration state of a device

  • Resource, class, and module: Components of the manifest, with the largest component (module) being comprised of smaller classes, which are in turn comprised of resources

  • Template: A file used to create a manifest, with variable names that will be substituted

In Figure 1-5, the engineer builds all the necessary files (1) and configures the device agent or external agent (2). The agent or its proxy then pulls the configuration details (3) and updates the configuration (4), when needed.

Chef

Chef, like Puppet, uses an agent-based architecture. Chef uses several important text files:

  • Resource: A configuration object whose state is managed by Chef (for instance, a set of configuration commands for a network device)

  • Recipe: The Chef logic applied to resources to determine when, how, and whether to act against the resources

  • Cookbook: A set of recipes about the same kinds of work, grouped together for easier management and sharing

  • Runlist: An ordered list of recipes that should be run against a given device

Chef requires on-device Chef client code, and many Cisco devices do not support Chef clients, so you will likely see more use of Ansible and Puppet for Cisco device configuration management.

Table 1-3 summarizes some of the most important features of Ansible, Puppet, and Chef.

Table 1-3 Anisble, Puppet, and Chef Comparison

Feature

Ansible

Puppet

Chef

Term for the file that lists actions

Playbook

Manifest

Recipe, runlist

Protocol used to communicate with network devices

SSH, NETCONF

HTTP (REST)

HTTP (REST)

Uses agent or agentless model?

Agentless

Agent*

Agent

Uses a push or pull model?

Push

Pull

Pull

* Puppet can use an in-device agent or an external proxy agent for network devices.

Study Resources

For today’s exam topics, refer to the following resources for more study.

Resource

Module or Chapter

Enterprise Networking, Security, and Automation

14

CCNA 200-301 Official Cert Guide, Volume 2

16

17

18

19

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.229.21