Chapter 4 Where to Start with Network Automation?
For diagrams, tables, or exact code formatting, .
o YAML file format. o Abstraction of data from device configuration. o Key-pair values. o Lists.
Create small templates that generate configurations:
o Jinja2 file format. o Dynamic templates. o Mix of static text, variables and programmatic logic. o Variables replaced with information from group_vars and host_vars. o “For” loops to iterate over lists. o Basic “if”, “else”, and “end if” comparative Boolean logic.
Create tasks:
o YAML file format. o Cisco ios_command module. o Call the templates. o Assemble the templates.
Create playbooks:
o Identify scope. Which devices to execute tasks. o Call the tasks. o Execute using ansible-playbook command and options.
Data Model Structure Like the investment and thought that went into the hosts.ini structure, a lot of up-front time and planning is required to build data model structures. Some basic formatting standards, variable naming conventions and a variable dictionary hierarchy should be established and followed rigidly.
group_vars As part of the repository structure there is a folder called group_vars, which is an Ansible specific folder used to setup data models for the groups configured in the hosts.ini file. Group variables are applied to all common hardware platforms or logical functions. If, for example, a common QoS policy is configured on all the distribution switches, abstract the QoS policy data into a model in the CAMPUS- DISTRIBUTION.yml group_vars file.
[CAMPUS-DISTRIBUTION] can be called as a group_vars by creating a YAML file called CAMPUS-DISTRIBUTION.YML inside the group_vars folder. This allows the data model to contain variables that apply to all devices listed in hosts.ini file subsections creating a golden configuration by platform or logical function.
It is a recommended practice to prepend all variables created in group_vars with a common identifier such as platform_, group_, or global_. For example, platform_defaults or group_vlans. Using this naming convention when writing dynamic templates allows for the intent to become obvious to the operator. It also points to a file in the group_vars folder as the source of the data and variable.
