05-21-2019 06:43 AM
All,
Not sure if this is the correct place to ask this question, but I was wondering if anyone has successfully done network refreshes with Ansible. In our environment we are currently deploying new Cat 9k switches and replacing older switches that in some cases were only Fastethernet. I'm trying to automate the copying over of the config process using Ansible. I can do a config backup, but I'd like to be able to loop over the config and change all of the fastethernet1/x ports to gigabitethernet1/x. I've just started with ansible and can get the config backed up, but I'm not sure how to go about the change. Not sure if a module will do this, or if there is a regular expression way to manage this. I'm just looking for a push in the right direction. If anybody has any ideas, I'm all ears.
Thanks,
Steve Hart
Solved! Go to Solution.
05-21-2019 06:51 AM - edited 05-21-2019 06:54 AM
Hi there,
You could create a task in the playbook to run after the backups are copied to the local server which would call a python script to parse the newly created config backup and find/replace the interface strings. The next task would then upload the adjusted config to the 9k.
Something like:
tasks: - <backup_config_task> - name: adjust interfaces local_action: command python interface_adjust.py {{backup_config_location}}
- <upload_config>
cheers,
Seb.
05-21-2019 06:51 AM - edited 05-21-2019 06:54 AM
Hi there,
You could create a task in the playbook to run after the backups are copied to the local server which would call a python script to parse the newly created config backup and find/replace the interface strings. The next task would then upload the adjusted config to the 9k.
Something like:
tasks: - <backup_config_task> - name: adjust interfaces local_action: command python interface_adjust.py {{backup_config_location}}
- <upload_config>
cheers,
Seb.
05-21-2019 06:55 AM
Thanks for the quick reply! I'll look into how to do a find/replace with python. I haven't got to the point of calling python scripts with ansible yet. I'll look into it.
Thanks!
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide