Templates and Hosts file

Let's take a look at the templates folder and the Ansible hosts file.

We'll cover the following

templates

The templates folder is part of the Ansible framework and is where Jinja2 dynamic template files are kept. Like all the other folders, templates should be structured to scale and organized logically.

In the example, there are three top-level folders: banner, configurations, and documentation. These folders will have subfolders by platform, such as ios or nxos.

The banner folder is a simple text file that contains the standard banner displayed on all devices when a user logs into the CLI.

The configurations folder contains all the dynamic templates used to generate device configurations.

The documentation folder contains the templates used to generate the Markdown automated documentation. These templates have a matching YAML file in the tasks folder that includes the module used to compile the commands:

templates
|
 ---- banner
      |
       ---- standard_banner.cfg
 ---- configurations
      |
       ---- ios
            |
             ---- 01_ios_global.j2
             …
             ---- 35_ios_host_interfaces_Custom.j2
       ---- nxos
            |
             ---- 01_nxos_global.j2
             …
             ---- 18_nxos_host_interface.j2

 ---- documentation
      |
       ---- ios
            |
             ---- 3k_documentation.j2
             ---- 4k_documentation.j2
             ---- 6k_documentation.j2
       ---- nxos

The hosts file

The Ansible hosts file needs to be stored in the root of the repository.

A sample hosts file can look like this:

[CAMPUS:children]
CAMPUS-CORE
CAMPUS-DIST
CAMPUS-ACCESS

[CAMPUS-CORE]
CORE

[CAMPUS-DIST:children]
CAMPUS-DIST

[CAMPUS-DIST]
DIST01
DIST02

Get hands-on with 1200+ tech skills courses.