I’ve got this Python script that’s been doing a great job collecting network info like VPCs, subnets, and IP addresses from AWS, GCP, and Azure. Now, I’ve been tasked with moving this script over to Ansible to take advantage of its automation powers.
I’m kinda torn on how to go about it though. Should I create my own Ansible module using the existing Python script, or would it be better to dive into Ansible’s pre-existing modules?
Any tips or past experiences you all could share would be awesome! Thanks in advance for any help you can offer!
dive into Ansible’s pre-existing modules!!
Understanding the general ansibke workflow and interaction of modules brings great powers and endless possibilities
With Ansible vs. Python, there are some things to consider.
[Ansible is not a programming language] (https://www.redhat.com/sysadmin/ansible-coding-programming). In this link you can see there are rudimentary programming features of Ansible, like conditionals, but it’s surface level when compared to scripting/programming languages
Execution Speed. A moderately efficient Python script will run circles around an entry level Ansible Playbook
While Ansible can programmatically harvest data, its bread and butter is configuring things in an idempotent manner.
We are doing some things very similar to what you are talking about and our approach will be to build an Execution Environment that can run the Python script, and then have Ansible execute the scripts with either the shell or command module. This will probably come with its own challenges, but gets our ad-hoc scripts out of our local PC/Single Server environments and into the AWX/AAP environment as a stop gap measure.
The next thing we plan to do is re-write the scripts using Ansible native modules, collections, and roles. This is preferred because it then becomes more supportable by another team if for some reason I am no longer managing the environment.
If the performance decreases too much, or we have to hack in too many solutions to a specific part of the logic, we will then look into writing a custom module or collection to tackle that need.