Ansible or Python?
In the world of networking right now there are many discussions about which network automation tools are the best.
But one of the most asked questions is Ansible or Python?
Ansible for network automation is the tool of choice for most network engineers who are getting started with network programmability.
Python is a general purpose programming language that is widely used across the world and has found a big following with network engineers and is now the programming language of choice for network automation.
Both Ansible and Python are very good tools for network automation but which one should you learn and use?
Reasons to use Ansible for network automation:
- Ansible is open source.
- Ansible is easy to get started with, whilst it is written in Python you don’t need to know any Python to use it.
- Ansible is agentless – unlike Puppet or Chef or Salt you do not need to install an agent. It only require SSH access to your network devices.
- There is a great community and plenty of support for Ansible.
- Very low barrier of entry
Reasons to not use Ansible:
- Ansible is considered slow compared to Python
- Ansible playbooks are written in YAML
- Debugging problem playbooks can be difficult
- Ansible can break between version updates
Reasons to use Python scripts for network automation:
- You are learning one of the most popular programming languages in the world today. Infoworld.com reports that it might overtake Java & C in a few years. https://www.infoworld.com/article/3401536/python-popularity-reaches-an-all-time-high.html
- Python gives you complete control over what you want to automate, you are writing your own custom scripts to perform whatever tasks you want.
- Python is quick, using tools like Asyncio or Nornir, Python wins hands down in a speed test.
Reasons to not use Python:
- Python has a higher barrier to entry and is harder to learn than
- If you are using Python within a team, everyone needs to understand it
So which is better Python or Ansible?
This really depends on where you are on your journey into network automation, how much you want to learn and how much you just want a tool to do a job. So let’s discuss these points one at a time.
- Both Python and Ansible are free to use
- Ansible has a much shorter learning curve, you can be up and running with Ansible in under an hour.
- Python does require more learning and would be considered to be the more advanced tool.
- Both are agentless, only using SSH to connect to devices.
- Python is quicker than Ansible, but that might not be a problem if you don’t have 1000’s of devices to automate.
- Both use human readable code, but Ansible is considered to be more human readable with it’s YAML playbooks. For someone who doesn’t know programming interpreting a Python script to automate network devices might not be that easy.
The answer to this question really depends on the type of person you are and how much you want to learn.
If you just want a tool that will take backups, push configs and pull data from your network, most will go for Ansible, that is not to say it is not a powerful too, it is. However the general thoughts on this question are that if you want to get started with network automation then use Ansible and once you start to find it limiting you i.e with speed, debugging or not being able to break tasks to different devices / vendors then most people will start to explore Python.
Then once you know a bit of Pyhon you could look at Nornir!
Nornir vs Ansible
Nornir is a Python automation framework that enables you to use the most powerful Python libraries like Netmiko and the use the inventory of Nornir to be able to run all your automation directly from Python.
Once you have tried Ansible and learnt a bit of Python, the tool a lot of network engineers are now starting to use is Nornir.
But at the end of the day any tool is only as good as the person who is using it. A carpenter with a blunt saw will be able to make a much better table than someone who has never cut a piece of wood in his life.
So try out a few of these tools, see which ones you like and make your own decision. Whichever one you decide to use, just get good with it and your life will be so much easier:
pyATS vs Ansible
Another tool that is gaining traction in the network automation space is pyATS. On it’s own this is a Python testing framework, but teamed up with Genie and it becomes a network testing powerhouse. Nornir in comparison is a Python automation framework that handles inventory management very well and allows you to run your Python Scripts. Team this up with pyATS and you have a great solution so there is no real comparison between pyATS and Nornir they really work together.
Frequently asked questions
Is Ansible a programming language?
Not really, Ansible is an automation framework that is written in Python and uses Playbooks to perform it’s tasks. The playbooks are written in YAML.
Is Ansible better than Puppet?
Ansible and Puppet are both great tools in their own way, It all depends on what your use case is, Ansible would be used for smaller deployments, whilst Puppet is better for larger deployments. However in the network engineer field Ansible is used more than Puppet as it is agentless.
How long does it take to learn Python?
Python is a big language and you can’t learn it all in 1,7,21 days as some books claim. However within a few weeks you can start to make things work with Python, the key to learning Python is to just keep going, it will takes years to become an expert, but in the world of network automation you do not need to be an expert, you just need to have a good understanding of how it works.
What language are Ansible Playbooks written in?
Ansible Playbooks are written in YAML format. YAML stands for Yet Another Markup Language, or YAML Aint Markup Language! Playbooks tell Ansible what to execute.
You might also like,
- Understanding the Ansible Hosts File
- Ansible vs Python – Which one should you learn?
- Ansible Vault Tutorial
- Cisco IOS Upgrade for switch using Ansible
- AnsbleFest London / Review
- How to install Ansible Tower
- What are the advantages of using Ansible Roles
- What is Ansible?
- Ansible IOS Command Example
- Backup Cisco Switch config using Ansible