#cisco #network #ansible #ccie #devnet #automation
GITHUB:
https://github.com/jb26444/ansible.git
Folder: Config-Generator-Local
Transcript:
Today I want to share the topic of how to create network device configurations from a template using Ansible. The Ansible playbook will be able to create multiple configuration files using a single template file and variables file. This is handy to deploy configuration for multiple network devices. I will show you how to do it for Cisco IOS devices, but because the template is a jinja file template, it can be used possibly for any network vendor - like Juniper, Fortinet or Palo Alto.
I don't use virtual lab today. I have Ansible installed locally on my laptop and that should be all that you need.
Before I begin with the lab please, hit the like button and subscribe to help me grow this youtube channel.
My Ansible lab has only three files. YAML Playbook file is an execution file that combines a variable file and template file to create configuration files.
Let's review the template file first. It is a jinja file with .j2 extension. You can take any piece of configuration and convert it to a jinja template. As you can see my template is a traditional Cisco configuration and has variables that need to be populated in double curly brackets with item dot and variable name and that is all that is needed. This is how simple it is to create jinja2 templates. The file should be saved with the j2 extension.
Now we have the template ready, we need a file with all variables that we want to add into the template to create a configuration file. The variables file is a yml file. And we just need to create a dictionary inside curly brackets where the variable name is with its value.. It is a yaml file so it starts with a tree dashes. Then I have a dictionary with the name "switches: and then keys and values. inside Ansible playbook I will call the switch's dictionary to find the values for the jinja template. I have two sets of keys and values in a variable file. But if you would add additional lines. The ansible playbook will create more configuration files. Based on the hostname.
Now we have template and variable files. Let's look at an ansible playbook. My playbook has the name config.yml. Inside the playbook we have a section for the name of the playbook - Generate configuration files - host is localhost as we run playbook locally. And we don't want to gather any facts. Then I have the name of the task - Config from template. Then comes the play itself. We need to specify template source and template destination. Template source is our switch-template.jinja and destination is our current folder and config files will be created with hostname as a name and with .txt extension. Now we just need to specify which dictionary needs to be used for the jinaj template and this is switched. Now we are all ready to execute the playbook.
Смотрите видео Cisco DevNet Ansible configuration from template онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Jan Blahuta - Network Architect 10 Февраль 2023, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 283 раз и оно понравилось 10 людям.