Skip to content

Python script for creating IOS/NX-OS configurations. It will take a template configuration file and a variables file. The script will read in the variables for each device from the variables file, and then create a configuration from each device based on the template file.

License

Notifications You must be signed in to change notification settings

jamiecaesar/ConfigMerge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ConfigMerge

ConfigMerge is a Python script for creating multiple IOS/NX-OS configurations based on a template. It requires the following:

  • a template configuration file
  • a variables file, which contains replacement values for every host that a config should be generated for.

The script will parse a list of replacement variables for each host from the variables file, and then create a configuration for each device based on the template file. In short, this is an automated "Find and Replace", or Mail Merge for configuration files. There are some additional checks of the data to help catch errors and/or missing data.

ExTemplate.txt is an example template file that you would use as input for the script. ExampleVars.csv is an example variables file. This file is in Comma Separated Value (CSV) format so that values can be easily added in Excel. This file can be generated by the script, after it has collected all the variables in the template file. Once modified for each device, is used as input to create individual config files.

##Additional Features (beyond basic find/replace)

  • Verifies the template has a unique key (default: <HOSTNAME>) variable. This unique key is used to identify each individual device/config that is being generated by this script.
  • Checks for duplicate hostnames in the variables file (in the case of copy/paste errors).
  • Will verify all variables in the template file are in the CSV file (and vice versa)
  • --key (-k) option allow changing the unique key variable to something different, in case the default doesn't work for your particular use case.
  • --single_mode (-s) option can be used when the script will only be performing find/replace logic on a single configuration file. This ignores the requirement for a unique key. It will also only read the first non-header line in the CSV file when creating the config.
  • --help (-h) option that explains the syntax of the command as well as available flags.

##Using the script

  • Once you have the "golden" configuration template. Replace any part of the configuration file that needs to be changed per-device to a variable name (i.e. <IP_ADDR>)
  • Once you have your template configuration file, use the cmerge.py script to create the variables CSV file with only the header row.
python cmerge.py <template_filename> -o <output_filename.csv>
  • Modify the output variables file by adding a line for each device with all the appropriate information.

  • NOTE: If you leave a variable empty, the script will delete any lines that contain that variable.

  • Run the cmerge script, using your modified .csv file as the input file:

python cmerge.py <template_filename> -i <variable_filename>
  • Gather your configuration files from the configs/ directory, which was created by the script.

About

Python script for creating IOS/NX-OS configurations. It will take a template configuration file and a variables file. The script will read in the variables for each device from the variables file, and then create a configuration from each device based on the template file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages