Generating VMX files

The last part is to generate the VMX files from the Jinja2 template. We will read the data from the Excel sheet and add it to the empty dictionary, vmx_data. This dictionary will be passed later to the render() function inside the Jinja2 template. The Python dictionary key will be the template variable name while the value will be the substituted values that should be in the file. The final part in the script is to open a file in writing mode inside the vmx_files directory and write the data into it for each VMX file:

from jinja2 import FileSystemLoader, Environmentimport osimport xlrdprint("The script working directory is {}" .format(os.path.dirname(__file__)))script_dir = os.path.dirname(__file__)vmx_env = Environment ...

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.