Learning Library

← Back to Library

Ansible vs Python: Best of Both

Key Points

  • The speaker argues that using Ansible and Python together, rather than choosing one over the other, provides a stronger solution for automating VM and application deployment on public cloud platforms.
  • Ansible playbooks, written in easy‑to‑read YAML and powered by reusable modules, excel at declarative infrastructure tasks like creating VMs, assigning IPs, attaching storage, and provisioning software.
  • Python scripts require deeper programming expertise and manual handling of cloud‑provider libraries, making them less approachable for simple automation but useful for more complex or custom logic.
  • Simplicity and shareability of Ansible make it ideal for enterprise automation initiatives, allowing subject‑matter experts in networking, storage, or cloud configuration to contribute without extensive coding knowledge.
  • Since Ansible modules themselves are implemented in Python, the two technologies complement each other, enabling teams to start with straightforward YAML and extend functionality with Python when needed.

Full Transcript

# Ansible vs Python: Best of Both **Source:** [https://www.youtube.com/watch?v=Nzq6fEr9SJ4](https://www.youtube.com/watch?v=Nzq6fEr9SJ4) **Duration:** 00:06:01 ## Summary - The speaker argues that using Ansible and Python together, rather than choosing one over the other, provides a stronger solution for automating VM and application deployment on public cloud platforms. - Ansible playbooks, written in easy‑to‑read YAML and powered by reusable modules, excel at declarative infrastructure tasks like creating VMs, assigning IPs, attaching storage, and provisioning software. - Python scripts require deeper programming expertise and manual handling of cloud‑provider libraries, making them less approachable for simple automation but useful for more complex or custom logic. - Simplicity and shareability of Ansible make it ideal for enterprise automation initiatives, allowing subject‑matter experts in networking, storage, or cloud configuration to contribute without extensive coding knowledge. - Since Ansible modules themselves are implemented in Python, the two technologies complement each other, enabling teams to start with straightforward YAML and extend functionality with Python when needed. ## Sections - [00:00:00](https://www.youtube.com/watch?v=Nzq6fEr9SJ4&t=0s) **Ansible and Python for VM Provisioning** - The speaker explains why combining Ansible playbooks (declarative YAML modules) with Python scripts (procedural flexibility) is the optimal approach for automating virtual machine creation and application deployment on a public cloud. ## Full Transcript
0:00okay so I've been tasked with creating a 0:02brand new instance of a virtual machine 0:05and our application on top of it on a 0:07public cloud provider now in my mind 0:09there is one of two things that I could 0:11do here I could use an anible 0:15Playbook or I could use a python 0:20script now you might be asking why I 0:23would do one versus the other so 0:26hopefully by the end of my talk here 0:28today it shouldn't be an answer versus 0:30python conversation no no it should be 0:33anible and python they're better 0:36together now let's get 0:37started okay so first let's dive into 0:40our use cases here when we're trying to 0:43decide between anible and python it's 0:45helpful to First understand what it is 0:48that we're talking about so let's look 0:50let's dive into anible first in anible 0:53we have playbooks and these are defined 0:55in yaml these are very simple to read 0:58even simpler to write simple diversion 1:00control Etc now in yaml we are 1:03leveraging what we call modules and 1:06modules uh represent sort of this unit 1:09of work that we are performing so we're 1:11able to Define what we're actually doing 1:14with that module within yam and this 1:17will allow me to say create the virtual 1:19machine attach a public IP address 1:21attach storage provision the application 1:24on top of all this infrastructure and 1:26we're good to go anible is really good 1:28at that declarative picture show me a 1:30picture of what you want and I will make 1:32it so now on the uh on the python side 1:36we're still working in you know a 1:38document approach we have our python 1:40script here but this requires somebody 1:42with innate knowledge of this fully 1:45featured programming language so to 1:47start out with an automated tasks we 1:49might we might have to first import a 1:51couple of libraries so you know this 1:54could be libraries to leverage 1:55automation within your public cloud 1:57provider but the point is you kind of 1:59already need need to know how to 2:01leverage these libraries and methods and 2:03things to go in and accomplish the same 2:05task that we've defined so simply with 2:08anible so that is the what what is 2:11anible versus what is python in this 2:14particular use case now that brings us 2:17to why why would we choose ansible 2:20versus python now why would you choose 2:23between one of the other well it comes 2:26down to that complexity and that 2:27simplicity so here we have something 2:30that's you know again very U very simple 2:33to Define inversion control and read 2:36it's also very simple now to um to share 2:39this within my team within my 2:42organization as a whole and so that we 2:44can we can much easier adopt an 2:47Enterprise automation Journey using 2:50something that's simple to Define and 2:52track as anible now that doesn't mean 2:54we're not going to have complicated 2:57tasks after all these modules that 2:59answer is is using within a Playbook are 3:02WR written in Python which brings us um 3:05we've we've cover covered the what the 3:08why and now let's talk about the who so 3:10who is engaging with with ansible this 3:13would be um maybe subject matter experts 3:16sometimes that really understand storage 3:18or networking or Cloud configuration and 3:20and provisioning but it could also be um 3:23something like a citizen developer right 3:26this is really easy to read and 3:28understand now on the python side we 3:31might be talking again about a subject 3:33matter expert but also a python 3:36programmer and these are people that 3:38have gone to school and are highly 3:40effective within this space so when we 3:43talk about ansible versus python it's 3:46really more uh relevant to say anible 3:48and python we still need these experts 3:51to write our complex automation for us 3:55that we can now leverage back in anible 3:58use anible as that thing that's easy to 4:00use Easy to call your python uh 4:03automation modules and and kind of 4:06separate it out that 4:07way so now that we've sort of uh covered 4:11our use cases and and compare the two 4:14solutions when would we decide to use 4:17anible versus python now it all comes 4:20down to that complexity again because 4:22just because we have such a simple way 4:24of defining automation doesn't negate 4:27the fact that we still need this anible 4:30is written on the backbone it its 4:32backbone is python right um if we didn't 4:35have python we don't have ansible and so 4:37it's incredibly important to maintain 4:40the subject matter expertise in a 4:42fully-fledged pro programming language 4:45but once it comes time to scale this 4:47automation out to the rest of our team 4:49to the rest of our organizations we need 4:52something that's a little bit more 4:53simpler to maintain and operate at scale 4:56and that is anle and the anel automation 4:59platform 5:00form so there it is you know at the end 5:03of the day I chose to write my task to 5:06automate this VM creation attach my 5:09external um IP address and storage and 5:12add the application on top because it's 5:14simple for me to write but also simple 5:17for me to pass off to my colleague to 5:19spin up another Dev instance when I am 5:22out of the office had I done this in 5:24Python yes would have been able to do 5:26the same thing but I might have been 5:28called on the weekend that I have off to 5:31go up and stand a brand up stand up a 5:33brand new developer instance for my 5:35application now that we understand why I 5:37would choose ansible over python or vice 5:40versa I think you should go out and try 5:42our interactive Labs page and this is 5:44where you will gain handson experience 5:46with anible 5:49automation okay thank you very much for 5:51watching please do not forget to like 5:53And subscribe to see more from this 5:58channel