Chapter 4 Where to Start with Network Automation?

For diagrams, tables, or exact code formatting, .

JOHN W. CAPOBIANCOPRINTED PAGE 73

 DHCP servers.  Switch stack configurations.  Power stack configurations.

Starting Small

The approach taken to network configuration management may very well determine its success. Do not try to solve everything at once. Break the network down into small modular templates that can easily be read, understood and updated by others. The templates should cover specific functions and features. These small templates can and will be assembled later at run time so do not be afraid to make very small very specific templates as opposed to large one size fits all templates. Use check mode extensively, refactor code, start making manual updates and corrections to the network. Try to achieve idempotency.

Coverage by Configuration Prior to building templates, create and name empty files in the approximate order the templated configurations are to be executed. It might not be possible to mirror exactly top to bottom configurations of a network device but that is not the goal. The goal is to ensure all the configurations match and will execute in a functional order. The exact line-by-line configurations do not need to match sequentially.

The number of templates created largely depends on the number of technologies and features deployed to the network. There are, however, some common configurations to every network. Here is an example library of small, modular, templates that can be used for a standard campus network. Use this structure to start a dynamic template library. The entire repository is available for cloning, using Git, locally to examine the logic in each template. Remember if platform_ or group_ prepends a variable it is stored in a group_vars YAML file and applies to a group of devices. If host_ prepends the variable it is stored in a host_vars YAML file. The templates are enumerated to control the serial order of operation in which they are processed.

 01_IOS_global.j2: o Contains device global configuration commands. o Static explicit text. o Logical operators. o Sample:

service password-encryption service compress-config hostname {{ host_defaults.hostname }}  02_IOS_dhcp_server.j2: o Devices that act as DHCP servers.

 03_IOS_management_source.j2: o Standardizes management traffic sources. o Applied across enterprise. o Sample: {% if platform_defaults.type == CORE %} ip radius source-interface Loopback0 logging source-interface Loopback0 snmp-server trap-source Loopback0