cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
962
Views
0
Helpful
2
Replies

How to use ansible to replace a config from a fast ethernet switch and add it to a gigabit switch

Steve Hart
Level 1
Level 1

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

1 Accepted Solution

Accepted Solutions

Seb Rupik
VIP Alumni
VIP Alumni

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.

View solution in original post

2 Replies 2

Seb Rupik
VIP Alumni
VIP Alumni

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.

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!