I have to say that is pretty good learning task how to get in to python/network. You can use Ansible or just python itself...I would start with learning how to use python to log in to device, then how to run a command.
For a start, please have a look at this. I wrote it while back. It could be a good starting script for you.
What i'm trying to do here is not configure devices, but to re-mediate something that is not required / correct the configuration on the device.
Simple way to put this, if a port is an access port then send the command STP portfast to it and if the port is trunk port then send switchport trunk encapsulation dot1q.
The task here is to achieve this using a single script.