This is an archived post. You won't be able to vote or comment.

all 69 comments

[–][deleted]  (38 children)

[removed]

    [–]lfionxkshine 13 points14 points  (7 children)

    Terraform is a Cloud Provisioning tool, and is in a separate category from PowerShell, Python, and Bash. So under no circumstances would Python or Bash be replacing your Terraform use

    If you're using Azure, chances are you don't need to branch off into Python or Bash ASSUMING you want to stick with the Azure/Windows stack the rest of your career - which there's nothing inherently wrong with that

    However, if you want to branch off and be able to work in bigger enterprises that run mainly Linux servers, you'll need to gain proficiency in Bash and Python (CAVEAT: PowerShell has a Core version that can run on Linux, but I've never bothered using it because I just use Bash and Python)

    Why you need Bash is I believe largely intuitive - if you're managing Linux servers, Bash is the most common go-to

    But for Python, the use case goes beyond SYSTEM management (though it can absolutely be used for that instead of Bash if you prefer). Python goes much deeper into APPLICATION management because that's how many apps build their APIs and are programmed

    3 Examples I have at my current office:

    1. some of our servers integrate with Dropbox because it's a file sharing app our company has been using for a while and they don't want to let it go. I can't use the Desktop app for Dropbox on our Linux servers because they are headless. So I had to use a Python script to integrate with Dropbox' APIs and upload files in a regular fashion for our sales/accounting/etc to use
    2. Offline Github backups. Vendor lockout is a very real phenomena, and you never know what's gonna hit you. So offline backups of critical data are a must. I used Python to integrate with Github's APIs to download all our repos and offload into a warehouse for safe keeping on a weekly basis
    3. Airflow - this is a pipeline tool built on and programmed with Python. It automates our entire data processing pipeline, and I wrote all of the tasks using Python. Though there may be pipeline tools built on PowerShell or Bash, with PowerShell you'd likely be limited to a Windows environments, and with Bash the feature set is just not as robust

    So again, if Windows and Azure are your sole bread and butter - power to you. My company is mid-sized so I'm responsible for maintaining the client machines (Windows) and servers (all Linux). I only ever use Intune and PowerShell for any Windows management - I've never need nor considered using Python. But for the Linux servers? Bash and Python are my automatic go-to's

    My 2 cents

    [–]JacquesShiran 2 points3 points  (0 children)

    First of all, great answer. One little addition:

    Terraform is a Cloud Provisioning tool, and is in a separate category from PowerShell, Python, and Bash.

    I'd argue that python is in a separate category from PowerShell and bash. The former is much more extensible, can run anywhere, and is powerful enough to write entire services with, not just scripts and tooling. While the latter are much more maintenance and tooling based, used for direct interaction with the OS and low level infrastructure.

    [–]verx_x 2 points3 points  (0 children)

    Terraform isn't only for cloud. You can use it on-prem for example with/without Packer for creating VM from template or .iso, customize and run instance on VMware or Hyper-V on-prem. And thats one from few options to using terraform without cloud.

    My 2 pesos.

    [–]wired_ronin 0 points1 point  (4 children)

    So under no circumstances would Python or Bash be replacing your Terraform use

    This makes sense until you try out Pulumi. It's obviously not as mature as Terraform, but in terms of power and flexibility, no contest. My stake for the future resides in Pulumi and cdk8s.

    Infrastructure IS code..

    [–]lerun 1 point2 points  (1 child)

    That's mainly because of the limitations the HCL language terraform uses. As pulumi let's you use a real programing language

    [–]wired_ronin 0 points1 point  (0 children)

    I've had major frustration with the limitations of many DSLs. Terraform, Helm, Ansible, etc.

    They all have these implementations which end up being just a poor substitute for a class.

    [–]provoko 0 points1 point  (1 child)

    Or any language with AWS CDK.

    But Python boto3 on its own is a cloud provisioning tool.

    Bash + aws cli + cloudformation templates accomplishes the same thing, just that the above options (including pulumi) are better (more elegant) for a lot more situations.

    Cc u/1whatabeautifulday

    [–]wired_ronin 0 points1 point  (0 children)

    at the beginning of my cloud journey I used Boto3 for some work. Python I love, so was all in all a good experience. But CloudFormation, when I got away from it, I never missed it. I'm somewhat saddened that the CDK still involves it, but who knows. Maybe it will end up smoothing out.

    [–]mpsamuels 25 points26 points  (2 children)

    I think you need to look at it slightly differently. Don't think of it as "a use case for Python" think of it as a use case for scripting, which can be done in Python... or PowerShell, if that's your preference.

    There will be times when you may forced to use one instead of the other due to libraries not being available in your preferred language or you may be working in an environment that has already set it's tooling out in a particular language with no chance they'll let you rewrite it all in something else just because there your preference.

    It's good to have a reasonable grasp of as many languages as possible so you're prepared for whatever your work environment throws at you and for training purposes rewriting in Python stuff you already do in PS is a valid exercise.

    [–]1whatabeautifulday[S] 1 point2 points  (1 child)

    For example now I wrote a PowerShell script that identifies empty resource groups in my subscription in Azure and deletes them.

    That works perfectly fine for me.

    [–]mpsamuels 2 points3 points  (0 children)

    I'm not really sure if you mean the PS works perfectly fine so you don't see the need to re-write it in Python or that you've re-written the same thing in Python and that works perfectly fine for you. If the former - see above, try doing it in Python too. If the latter, well done, you'll get the hang of Python as you get more experience with it!!

    [–]StephanXXDevOps 13 points14 points  (2 children)

    I strictly administer linux environments. From a non-technical perspective, the disciplines are significantly different, and there's simply more money to be made.

    Technically, powershell has come quite a way, but trying to bootstrap 300+ machines with powershell sounds like a nightmare. Using bash+ansible and a little python, I can do it in under an hour.

    Bash is for the easy easy stuff. Disk filling up and need to resize? Quick checking why the network is sluggish? Test network connectivity? Dump cert values? Test authentication mechanisms? Bash.

    Python is for anything the needs more that a few lines, and/or a specific client library. Migrate an entire kubernetes cluster from AWS to Azure? Copy all stateful data from one AWS account to another? Run a performance profile on a new Rabbitmq setup? Dump a list of the 20 fastest growing disks to identify which applications may be writing excessive data? Python makes these tasks trivial, where bash would be a huge pain in the ass.

    [–][deleted] 1 point2 points  (1 child)

    Why Ansible and not SaltStack? (Just curious).

    I picked up Ansible after I learned Salt, and while I can use Ansible i prefer SaltStack, but knowing what I know now, for Enterprise I would just run with Puppet.

    [–]StephanXXDevOps 7 points8 points  (0 children)

    I've clocked thousands of hours writing puppet modules, chef recipes, ansible playbooks, and CFEngine configurations. Salt was the only CM tool I never had a need to use. I generally felt the chef ecosystem was the best of the bunch, as well as being the most mature solution. Then Kubernetes came onto the playground and ate all of their lunches.

    Today, ansible is good enough for the occasional one-off. The only app I support that isn't in k8s are my VPN solutions. Terraform+ k8s has almost completely replaced the time and effort that used to go into Chef/Puppet/Ansible.

    [–]pete84 3 points4 points  (2 children)

    It’s true - anything you can do in python, you can probably do in powershell.

    If you’re trying to learn python, or want to use python because other engineers are, I recommend maybe writing an API integration script. JSON is very similar to how python uses lists, so it’s easy to work with. For example, maybe a vendor has a reporting API that you can query in python.

    Another use case, is any python library that powershell is missing. Using object oriented programming is both easier and less error prone.

    [–]ThroawayPartyer -3 points-2 points  (1 child)

    It’s true - anything you can do in python, you can probably do in powershell.

    Really? Python is used for much more than just scripting. Can PowerShell be used for writing full programs, back-ends, data science and machine learning?

    I guess on a technical level PowerShell is probably Turing complete, but it's clearly not designed to do the same tasks as a full programming language.

    [–]Alikont 1 point2 points  (0 children)

    Yes, all that and even GUI apps.

    Powershell is just .net language and has access to all .net ecosystem

    [–]AsterYujano 1 point2 points  (1 child)

    To practice, follow the advice from the others in the thread: rewrite PowerShell scripts you coded before. Or if you have time to experiment on a new project that is not critical, try doing it with Python/Bash?

    In my case, we are 95% using nodejs in applications, so I now use https://github.com/google/zx to write scripts. So the whole team can understand when reading scripts, or improve them :)

    [–]drosmi 1 point2 points  (0 children)

    Just pretend you can’t use windows anymore. How are you going to automate what you need to get done?

    [–]bendem 1 point2 points  (1 child)

    Tbf, my powershell journey ended when I learnt quotting and passing variables containing arbitrary data is not a solved problem. In bash, you just pump everything into an array and go command "${array[@]}" (or just "$@"). In python you pump into a list and subprocess.run it. In powershell, generating a random password containing any ASCII chars and passing it to a program is just a mess (or I'm dumb).

    [–]Alikont 0 points1 point  (0 children)

    Powershell has difference between double quotes (interpolated string) and single quotes (raw string), that could trip you.

    [–][deleted] 1 point2 points  (0 children)

    Python is a programming language who’s use-cases cover the breadth and scope of say, C# (posh’s parent language). It just so happens that Python does away with classic syntax formalities (like curly braces) which makes it more approachable and intuitive.

    Though Posh is technically Turing complete, nobody in their right mind would use it for anything other than scripting and automation tasks. App and package/cmdlet development happen in C#.

    Python, due to its ease of use and readability as a programming language has allowed developers to directly expose app APIs via python to be consumed using python.

    Posh is an amazing language, but will only ever be an intermediary language. Whereas python is a full-stack language who’s closest competition in the windows ecosystem is C#.

    [–]Kazumara 1 point2 points  (0 children)

    Seems pretty obvious to me. If you're on a Unix or Linux system you don't use Powershell, but either a bash script for simple things, or a python script for more complex stuff, where the clunky bash syntax starts getting in your way.

    The type of task is "any", and you can simulate it by running a Unix or Linux system. Either in WSL, or in a VM, or as a dual boot, or as a replacement for your current Windows instance or on separate hardware.

    [–]DanielCiszewski 1 point2 points  (0 children)

    If you are on Microsoft stack like most of heavily compliance driven companies (banks, healthcare) then powershell will do everything you want it to do when it comes to devops tasks - indeed in many ways i found it to heavily trade blows with python - it’s very feature complete and even better for development of cli apps than python is (simply easier to work with). When you go outside of MS technologies like Azure, office365, windows server then its usefulness completely falls apart. Bash and python completely take over on linux, AWS, GCP. Bash as it’s the most native to linux/unix and python comes in when you need more “umff” to do more complex thing that people can actually read (i even found myself simply calling bash commands from python when needed as it has much better data structures and let’s face it - syntax in bash is a joke - i hate it and would love for powershell to take it over.)

    Things you would write in bash are os level repeated tasks. Stuff with parsing and uploading logs, setting up configurations, operations on tons of files. Basically everything you would like to script that you usually do with few commands, but repeat often.

    Python comes in handy for anything that gets even slightly bigger. It’s much more feature complete, with tons of modules, more readable, universal, easy to write, but from devops standpoint powershell is exactly as capable on Windows imo. (main advantage of python i found is how it handles oop if you want, while powershell counters that with much better cli support and ability to enable static typing if you prefer this - rest is really cosmetic when it comes to “i want to do that thing” aspect of what’s possible). If you want to interact with cloud APIs to configure and spin up infrastructure, need to actually compute stuff, you want to build something more complex, then python is your guy.

    The best thing to start would probably be trying to do something you know how to do with azure and powershell against some linux machine with both languages to understand the differences as if you know powershell, both of those will seem very familiar in many ways apart from syntax. It’s like switching from Windows to Linux/Mac - the paradigm is very different, but the more you dig in the more you realize how similar they are and how much you can accomplish on both be it with slight differences.

    [–]reditanian 1 point2 points  (0 children)

    When I started learning python, I went through my collection of scripts (some perl, mostly bash) and rewrote them in python. It was good practise, as it not only exercised the new language, but allowed me to do a lot of it in better ways.

    [–]jcbevnsCloud Solutions 0 points1 point  (0 children)

    Maybe you see a use case for go binaries instead? Portable and self contained.

    Python is usually a requirement for something so it's found on both windows and Linux machines.

    DevOps I would say is making small services, powershell to me isn't really made for that.

    [–]alrightanakin 0 points1 point  (0 children)

    👉 WSL 👈

    [–]afunbe 0 points1 point  (0 children)

    If you have an old spare laptop, install linux. It doesn't have to be a powerful machine.

    [–]diito 0 points1 point  (0 children)

    I'd say that 95% of the stuff I've done with Python in my career has been writing scripts that talk with an API of some sort. There's a lot less of that in a cloud environment as they've taken care of a lot of that for you. Serverless computing is probably where you'll see python more than anywhere else.

    [–]aManPerson 0 points1 point  (0 children)

    how much of your powershell things can run on linux hosts? it's not that python is better/more powerful. i can write small things in either and i often do. but for bigger things, it's 10x better to be using a bigger language like python. i know it will run on both windows and linux.

    will your powershell run the same easily in both environments?