How to use Python in Devops

Posted on July 15, 2019
python
devops
9805

Python in DevOps

 

Nowadays everyone is looking at DevOps and Python. So if you want to know why the python is important in DevOps this article may help you.

In DevOps culture, we are required to do a lot of automation using tools and scripts. Python will provide huge open libraries and modules to help in that automation.

If we want to write a script to automate a task Python is a better option in terms of platform independence, easy to write and integrations with all tools. In Python there are so many modules available as open-source which supports several tools.

 

 

 

 

 

Below are some useful modules in python to write automation scripts.

 

Gitapi is a python module which will interact with our version control system, so if you wish to set properties or some useful functions dynamically you can write a python script using this module.

 

Continuous integration we need to add some scripts to perform some of the jobs. If we write those scripts in bash or PowerShell then we will face a problem when our CI environment is changed. So we can use python to so that we can move our environments.

These environment-specific or Operating system-specific details and methods are handled using os and subprocess modules, and we have networking modules also.

 

If we have our infrastructure is in the cloud we have their REST APIs but in python we have their SDKs to implement infrastructure related automation scripts.

We have boto sdk module for AWS, for Google Cloud Platform (GCP) we have google-cloud-storage sdk. We have OpenStack modules to deal with all operations in public/private clouds of OpenStack.

 

All of us heard about Configuration Management tool Ansible and that is written in Python, If you are using Ansible and need to write any custom modules in ansible you have to write python modules only.

In puppet also we can do lot more automation scripts with python.

 

We have testing frameworks in Python as well, we can use selenium module for web automation testing using python and these are all very easy to implement. Even Django uses built-in Python testing framework for writing UnitTests and all.

 

For database management kind of task we have python modules for almost all databases such as MySQL, PostgreSQL, Oracle, mongo etc.

 

If everything is ready to deploy, even in this deployment stage also we have very useful python modules such as fabric, fabtools, cuisine which are used to deploy applications on your nodes using SSH.

In some cases we need to deploy our application in Paas(Platform as a service) environment like cloudfoundry, IBM bluemix etc. For this cloudfoundry also we have a module in python called cloudfoundry_client.

 

In order to monitor our applications or resources we are using Nagios, graphite etc. These modules can be managed easily by using python, we have different modules to support these tools also.

 

If you clearly observer the above sequence, we can relate our DevOps principles order. So in every stage of Software Delivery Life Cycle we can use python to automate things and even build the softwares like Ansible, Fabric, Django. So python in DevOps or python usage in DevOps is essential to make automations easier.

 

I can conclude that we must know any scripting language to automate our day to day tasks with so many different tools and Python is the best suitable option for this which will provide all integrations with those tools.

Not only in DevOps Python can be used in so many areas to implement, develop, help and improve the systems.

 

Lastly Python is not only the best fit for above-mentioned scenarios, we can use ruby also if it is the best fit for any case, but I am concentrating on only python in this article.

 

If you know any cool modules or implemented any useful modules comment below.




1 comments

devendra
devendra

I want to get your attention to the Python modules to succeed the automation in DevOps. Read 8 Python Modules to Induce Automation in DevOps here - https://www.gspann.com/resources/blogs/8-python-modules-to-induce-automation-in-devops

Please log in to leave a comment.