cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
288
Views
0
Helpful
2
Replies
Highlighted
Beginner

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

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
Highlighted
VIP Advisor

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
Highlighted
VIP Advisor

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

Highlighted

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!