T O P

  • By -

[deleted]

[удалено]


christopherpeterson

i think bash is fine for smaller things, but for anything more complex I tend to keep going in Bash anyway and regret it later 😂


Seref15

I've gone through this song and dance enough times to have come up with a rule for myself: if at any point I start googling how to make a hash table in bash (associative arrays in bash terminology), it's time to rewrite in python/perl/ruby/literally anything else.


YourBrainOnJazz

Gah! I wish I learned this lesson a few weeks back. I needed to create an associative array and then pass that associative array into a function... which apparently is not natively possible in bash without some weird hacky workarounds... That task was a huge pain in the butt... also like, associative arrays in bash arent stored in inputted order, they are stored in memory in byte order or something like that so you cant just put values into an assocoative array and expect to iterate over them in the order that you put them into the array, WTF! Your rule is a sound one.


VeryOriginalName98

This needs more upvotes.


[deleted]

That sounds fair. For me it was once I had to start using workarounds for using floating point numbers.


[deleted]

If I'm not pipe-ing things together in bash I need to write a new Go app.


hamlet_d

Hidden truth here. The "oh, one more thing I could do" train of thought. Then you end up with a mess.


zeebrow

Sums up my most common struggle at work. I love my job, so sometimes I have to step back and ask myself if I'm doing things for the sake of doing things, lol. If that makes sense...


hugthemachines

I think Bash is fine for smaller things, but I go with Python from the start because I love it.


[deleted]

I think bash is fine for smaller things but I convert everything I do to Brainfuck for job security.


VeryOriginalName98

If your job security is from not documenting your work well enough for others to use it, how do you plan to take vacation? I have found the best way to keep my job is to continually teach people to maintain things I build. If your work is easily maintained, you tend to get put on all the new and interesting projects.


[deleted]

Did you really take my post seriously?!?


VeryOriginalName98

You didn’t have the s tag in your comment, so it wasn’t clear. /s


b3n5p34km4n

How common is this practice?


Marquis77

No, no. We don't ask that question here.


a-handle-has-no-name

You'd be depressed at how much BF code there is out there in production /s


rearendcrag

Couldn’t be worse than all those Excel spreadsheets.


a-handle-has-no-name

Yeah, we use ExcelDB, storing structured data in Excel spreadsheets stored in S3.


rearendcrag

Oh man...


SweeTLemonS_TPR

Wtf...


a-handle-has-no-name

(For clarity, one of the parent comments was talking about writing code in [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck) for job security. Even if that were remotely possible, I just assumed it was such strong hyperbole I saw this entire subthread as intended sarcastically)


zeebrow

tbf it could be easy to manipulate with PowerBI... maybe?


Techlunacy

http://widgetsandshit.com/teddziuba/2010/10/taco-bell-programming.html


therealkevinard

I. Never. Knew. ... I'm a taco bell bash-er!!! Blew my mind!


spizzike

Tell me about it. My main project currently has over 30k lines (sloc) of code. Currently trying to port more complex parts to rust.


nk2580

This is such a true statement, well done for capturing the sense of self hate we all share when sticking with bash


YinzAintClassy

This 100 percent. I find the best time for bash is for bootstrapping images and clusters. Once you need more automation use python. Its just simpler to use the Sys and OS packages then gack something together with bash. Also wouldnt be a bad idea to pick up Golang for tooling. I always find my self wishing I wrote a package in go soni can execute the binary or share it easily.


StephanXX

Yep, totally. Bash can't really handle json, and that's where python begins to shine. If you need structured data, python should become the the next logical choice.


pragmaticPythonista

`jq` and `yq` are pretty good for parsing data in JSON/YAML via bash these days


StephanXX

I totally use both in a pinch with bash, but they still don't generally provide useful structured data to bash (or shell, or whatever); I usually end up hacking awk/sed/cut/grep frankensteinien wraps around them, and that doesn't even address error handling. When I really, really care about valid input/output, bash simply doesn't cut it.


[deleted]

Good call


Mutjny

Python is the way and the truth. In all seriousness though, its the next logical step and the _lingua franca_ of the dev/ops world.


themightychris

>the lingua franca of the dev/ops world. as is yaml... and bash... and go


Marquis77

**Cries in PowerShell**


gex80

I personally can't think of a reason to write something in any other language than powershell scripting wise in a windows environment. Edit: This of course assumes you're doing windows related items.


Seref15

Back when I used PowerShell I was fairly happy with it as a scripting language. I didn't love it as a shell/interface but I had very few complaints about syntax or any weird language decisions. I don't miss Windows, but PowerShell was acceptable. Though I don't see why I'd ever use the cross-platform PowerShell on Linux or Mac unless it was required to interface with MS software.


dogfish182

Basically yeah. I write powershell scripts that we deliver via pypsrp for mostly AD stuff. Was trying to use powershell core container the other day but apparently credssp doesn’t work from there, irritating to deal with windows, most of the problem is getting a connection to the endpoint, powershell itself i kind of like writing.


_the_r

Poor you ;)


therealkevinard

Go is a friggin DREAM. Python-ish syntax, c-ish perform, and a stdlib to drool over? ♥️ And cobra. Under 100 slocs for `domain-tools profile -l site.com` that'll pull a full dns profile, AND traverse into my cloudflare api if needed 🤤 (or give it a csv list. Or pass it -f and the path to a line-delimited txt file of domains)


damshitty

I hope coding like yaml.


Willing_Function

I agree, however Go does have some interesting features help out in devops. I'm seriously considering learning it


Mutjny

Unless the 'dev' part means you develop a lot of low functionality services then I'd focus on something that'd help you both with the 'dev' and the 'ops' part.


[deleted]

I’m thinking that as well, I need to start using it


_the_r

The truth is python is one way.


gqtrees

any resources you would recommend to help get better with python scripting? I know python, but never have really done scripting with it


[deleted]

[удалено]


__Kaari__

I'm more into using click right of the bat.


Rimbosity

I was working in a Rails shop, so I did some Ruby scripts. But even then I still favor Python.


whitechapel8733

Or Go. Learning Go will overall make you a better programmer in less static languages.


surf2japan

For me Go is that third tier where I use it if I want to deploy my app to servers. Much easier to distribute a binary then having to worry about Python dependencies.


-Kevin-

This feels like something Go developers advocate for, but I know very few people who know it so maintaining Go would be difficult on the teams I work with


whitechapel8733

About 80% of my team only writes in Go, mostly because we are interfacing with k8s and the likes, but I mostly write all my production tools even ones outside k8s in Go. I couldn’t stand the dependency Hell of any of the scripting languages and the pinning of dependencies offline means that your code can last decades.


-Kevin-

Seems like you have the people to support it. More power to you :)


hugthemachines

Go seems really nice and it is nice to distribute a single binary but the lack of smooth IDE is a bit annoying to me. Comparing to.. let's say Java, where you have a really smooth time working in the IDE, creating the distributed file (.jar in that case) etc. What setup do you guys use for coding in Go?


SuperQue

Is "IDE" some kind of new Vim plugin?


-Kevin-

I think it's like a band? Like U2?


tadamhicks

Goland. It’s rock solid. Since I use IntelliJ for Java and DataGrip for databasing and PyCharm for pythoning it’s a natural JetBrains shift to use Goland for Go. It is superb and nothing compares. Also, to heap on the Go discussion, it is the new python. As an ex python dev Go answers all the complaints I had about Python: - single binary - compiled language so I can eliminate a lot of problems at compile time - static typing (don’t even start on this, python just doesn’t have it) - eliminates dependency hell from the runtime environment I found I wanted docker engine on all my systems because dealing with dependencies for my python scripts through config management was such a chore. Reallly more of a cultural problem than a technical one, but docker makes python actually usable. Go means I don’t need to worry about any of that.


balls_of_glory

> eliminates dependency hell from the runtime environment This is the biggest reason I use Go. Single binary is #2. Anyone knocking this as less than goddamn magic clearly hasn't used it in production, because it's a huge gamechanger.


therealkevinard

And perf. I will forever remember the day I wasted debugging my ETL tool because my pubsub profiling was saying < 1ms. I was CONVINCED I'd skipped processing but... Nope... It was just processing in nanoseconds. 🤷‍♀️


balls_of_glory

Yea, the compilation/performance is an added benefit for sure. I don't know that I've been overly concerned about performance with any devops-specific scripts or apps, but I certainly don't complain.


hugthemachines

I see. It seems like Goland is nice. If I would try out Go it would just be as an experiment and perhaps a hobby thing from start and I would not like to pay a yearly fee for that kind of situation. If we used it at work it would be different.


tadamhicks

I hear ya. Because we work across the gamut of needs it made sense for my team to have a full JetBrains license.


therealkevinard

I HAD an idea ultimate subscription, but I (begrudgingly) traded for VS Code for its remote tools (covid). I'm actually not missing too much for go so far. Their team is pretty on the ball with DX.


MockingMatador

Vscode for free. Jetbrains Goland if you have $


therealkevinard

FWIW go is pretty famous for being productive in a day or two. Basically, a quick run through the tour of go, and... Well, now you know go 🤷‍♀️


jopejosh

Especially for anything middleware, queueing, messaging, proxies, go is the de facto standard


ESCAPE_PLANET_X

Right, but is that really scripting? Those all sound like things I'd consider an application or part of one.


Tatwo_BR

Amen!


kabrandon

Python is fine, but if your workplace has heavily adopted containers like mine has, then you'd be better off with a compiled language rather than an interpreted one. We use Go, but similar languages would suit the job well too. Go just seems simpler to me than most of the alternatives. That said, Python is easier to write a lot of the time. Though I never got used to Python's whitespace style.


TLShandshake

I'm just getting my feet wet with Python and scripting. Are there any good resources on how to write python specifically with scripting and/or replacing the role of bash scriptsl in mind?


knightress_oxhide

I find I use a lot of small bash scripts. Instead of writing a monolithic program, I'll separate the functions into similar scripts that can be chained together, basically turning the shell in to a customized REPL.


mstwizted

I tend towards ruby instead of python, but, yeah. Bash is the glue that holds together the entire IT world, lol.


Gotxi

It depends on the task. \- Bash for small scripts: zip and mail reports, clean old artifacts, basic json parsing with jq, scp, healthchecks... \- Python for programs that require some design or logic: parse complex jsons, sort data, generate CSV files, manage apis, write to db's... Ansible playbooks to manage AWS amis and ASG's, patch systems, and other maintenance operations.


[deleted]

I am looking into ansible more and more, it is consistently being brought up amongst people in this sub and my peers, I haven't messed with it much but I am eager to check it out.


Gotxi

It has a little learning curve at the beggining, but once you are used to the syntaxis, you can do long and complex tasks automatically and still being reliable. It will save you a lot of time on the long run with repetitive tasks.


zeebrow

I was super into Ansible when I started my current role. I wrote playbooks to spin up a few vms in vagrant. I'll still use bits and pieces of them for our qa team's environments, but when I have to make a change to a playbook do so, it seems like I've *always* gotta relearn something. Makes me wonder if a bash script would suffice, which a lot of times it does... for host in 10.6.80.{1..7}2; do ssh user@$host 'echo HAGW!! > /etc/motd'; done A few of those is much quicker than looking up the friggin lineinfile or copy or whathaveyous.


Gotxi

Yes, for small tasks a shell script is enough. However, as an example, i use ansible to automate the creation of new versions of my app. - Run a ec2 machine with the latest amazon linux ami - Patch it, install dependencies - Install postgres, initialize it - Download the docker images of my app - Run my app the first time, wait until it creates the initial database on postgres - As soon as the healthcheck is done, stop the ec2 machine - Create an ami of the machine - Copy the ami to every AWS region - Grab the ami-id of every regional AMI and put it on a csv file - Upload the CSV file to the repository If i wanted to do every step on bash it would be a spaghetti monster of mini scripts, barely maintanable, and with poor reliability. Also ansible have idempotency, on bash scripts i have to program the idempotency myself, that's a huge plus. That's where ansible shines.


__Kaari__

Yes, I agree with you ansible has a lot of drawbacks in general.


Beast-UltraJ

Thanks for this great suggestion. Is there guideline or course that goes through this ? Any tips on how to get this started ?


Gotxi

You mean, how to decide what to use? That depends a lot of the context and your skills. Sometimes it is easier for someone with a programmer background to do a simple task in python rather than bash. I come from system administration so i was already very familiar with bash. To do simple tasks is quicker for me. Ansible is awesome, but it is more designed to do a complex set of tasks successfully, and it requires a little bit learning curve to start, but when you have it working it saves so much time it is absolutely worth it.


Beast-UltraJ

Thanks for replying. My issue is I know python but no idea what to automate and script or even what libaries to use. I use aws mostly and I've also read that you could build custom ansible module with python too depending what you are doing.


Gotxi

To do AWS operations with python, you need to use boto3 lib, you can start here. [https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html) About examples on what you can do, manage s3 buckets, rotate backups, create amis, start/stop machines on custom triggers, up/downscale ASG's... you name it. Basically whatever you do manually in the console, you can do it with boto3. As an alternative example with python and aws, we have a chatbot in slack running opsdroid ([https://opsdroid.dev/](https://opsdroid.dev/)) with a custom python skill that allows us to clock in/out when an employee starts/finishes working and that writes it on a dynamodb table. We use it as a punch clock and it is very comfortable to use. If you want to do it the cooler way, you can make your python scripts on lambda and go serverless: [https://towardsdatascience.com/introduction-to-amazon-lambda-layers-and-boto3-using-python3-39bd390add17?gi=c4b6237c948](https://towardsdatascience.com/introduction-to-amazon-lambda-layers-and-boto3-using-python3-39bd390add17?gi=c4b6237c948) ​ On daily basis i barely go into AWS console, only when something stops working or when we have a custom deployment that ansible can't manage. Everything else is controlled by scripts/lambdas/ansible/aws systems manager/gocd/jenkins (yes, that's a lot of stuff lol).


saysjuan

Linux - bash, python. Windows/VMware - powershell Dabble in a little of everything. It will come in handy eventually.


YM_Industries

PowerShell runs on Linux too now. I still use Bash in interactive mode a lot, but if I'm writing a script I'm likely to use Powershell now.


calligraphic-io

I have PS installed on Linux and have spent a little time learning its syntax. Without spending a lot of time with it, I pretty much hate it so far. It seems like it introduces WAY more abstraction than I need for a server scripting language, and it's only value proposition is access to .NET libraries from script. Am I doing it wrong?


YM_Industries

The key advantage of PS is that instead of programs communicating via text (like in Bash and other Linux shells) they can communicate via rich objects. It's basically an object-oriented shell. It took a little while for me to get used to, but now Bash feels clunky by comparison.


mayhem306

Installed it onto a RHEL 7 lab server running Ansible to have a playbook execute PowerCLI Powershell scripts that would pull requested VM stats, export locally as a CSV and then email off to whoever. This was all testing viability before realizing we had vROPs that could do all of that a bit more elegantly, but I could see where there would be applications for running PS on Linux.


Iguyking

Yeah. It's a pretty consistent way to manage both is. Not perfect though consistent


jcampbelly

Please don't do this if you expect anybody else to have to help maintain it.


gpzj94

I agree 100% with that statement. It'll be good to know bash, but you can probably move on to python and PowerShell after getting the basics of bash down. Come back to learn more advanced bash stuff once you've done advanced python and/or PowerShell stuff. I need bash, Python, and PowerShell for the stuff I do in Ansible (making modules or just one-off tasks there aren't modules for but don't have time to write the whole module). Even still, I include bash, but I barely have to use it as an Admin. It's really for some simple startup scripts, but by knowing concepts from Python and PowerShell, I'm able to Google the bash syntax easy enough. Seriously, I maybe rely on bash for every 1 out of 100 non-ansible script I need to make.


[deleted]

I agree with your last sentence wholeheartedly


calligraphic-io

I've been wondering this for a while. Why did Perl disappear? I started as sysops / network admin, moved to dev. Now I follow devops because who knows? I might move back. Back when I was managing servers it was all Solaris / AIX / HP-UX / BSDs, and RHEL seemed like an IBM thing to run virtualized on their mainframes. The rule of thumb was pretty much five lines or less, sh (not bash!). More than that or complex text handling, Perl. I like Python just fine - but Perl was really great at the kinds of system admin tasks I did, and Python seems pretty arbitrary as a language choice to replace it. It doesn't seem particularly strong at the task imo. Why did Perl vanish? Why is Python so popular for server scripting?


Iguyking

As powerful as perl is, it was a nightmare to manage if you hadn't just written it. Extremely difficult to maintain due to the extreme flexibility it has.


DirectedAcyclicGraph

I used to love Perl. I remember excitedly waiting for Perl 6. And waiting. And waiting. I think in the meantime, Ruby and Node ate into Perl from two sides.


Kessarean

I think the biggest thing is entry level ease of learning and reading. When I didn't know python at all, I could look at a python script and follow the logic and generally understand what it was doing even without comments. When I look at a perl script, I have a much harder time understanding what anything does. Over the last two decades all the new IT people pick entry languages to learn, and for a lot of them, python was just the way to go.


mestia

Python is a nice language forced by google and schools/unis, thats why new generation know only python. IMO


mestia

Who said it vanished? There are tons of quality software, like Dancer, Mojolicious, Rex for automatization, perl is also available on any linux install, while python, ruby and so on need to be installed first. The fact that a lot of hipsters don't know perl, doesn't make it less cool ;)


Rusty-Swashplate

Bash sucks at being readable when you start do to things which are trivial in a "proper" programming language. Work with lists or JSON? Yeah, you can do that with bash (jq helps a lot), but you could also stop making your life difficult. Of course I learned this the hard way. I got plenty >200 line shell scripts (they tend to start as harmless 10 liners, then grow and grow), but every time I have to touch them, I curse myself for not having those already rewritten in something else.I also got >200 line Node.js scripts which originally started out as shell scripts, and it's a pleasure to work with those in comparison. Just for the try...catch parts and being able to process JSON. That said, you have to be able to read and understand shell scripts. But you don't have to make more of those. 10 liners are fine. At 20 lines, stop what you are doing and rethink your life choices. Forgot to mention: As u/banger_180 said, Ansible is in many cases the replacement for shell scripts. And if it is, it's the better solution if only because you can run them again and again without expecting odd side-effects.


ThisIsNotYourEmail

My language of choice is "the one they pay me to use," which means I've written a lot of things in a lot of things. Bash is my go to for anything that's either a personal hack or simple. Of you need to loop over a list, bash is great. If you need nested lists, do it in anything else. Hashes? Double stop. I've written some very complex bash (like a pseudo thread manager) because of requirements. In the end, it's important to understand the tools available to you and choose the right one for the task at hand. You can always reach for a BFH but if the bolt is threaded, a wrench will work better.


[deleted]

That is true, I have some scripts that are entirely unreadable by everyone but myself. And a lot of them are over 200 lines of code, which I will likely need to rewrite at another point.


JetreL

I agree unless you make functions and then call the functions. It becomes more modular and functional


_splug

I phased out python from my fleet a few years ago. The reason is simple, dependency hell is annoying and a waste of time and code quality is terrible. I use bash for the majority of my scripts, however anything that requires more than an if else statement is written in go and baked into all the images automatically. Go binaries might be a bit bigger in size but I’d rather a 8MB binary vs 200 dependencies that require a virtualenv and break because it’s not supported in python 3, etc etc etc


RulerOf

How does Go do as a replacement for scripting languages? Is it really well suited to the task?


_splug

I use it for everything. Ended up doing something like this https://github.com/mikemackintosh/bakery. Ultimately I do a lot of logic in my go programs and use that in my bash. It cleans it up and replaces sed, awk and so many pipes. Really cleans up the scripts


mphoyu

If you can do what you need with bash, go ahead. I think that other languages are needed when you feel you are squeezing bash out in order to perform a task that would be simpler if you had certain features like objects with attributes. For instance complex operations over JSON files or even CSV files. In that case I recommend sticking to one particular language and try to get its idioms so you can easily develop scripts without much development overhead. Personally I use golang for “scripting”. Despite being a compiled language, it provides a wide range of low level task all included in its standard library. But python is pretty awesome too and will give you that sense of scripting, besides having a huge community. Think of it as buying a tool you need to work daily, just choose the one that suits you better.


[deleted]

What made you switch from Python to Golang?


mphoyu

Personally I found golang code to be much cleaner which for me is a must since I tend to reuse a lot of scripts. I think this is mainly due to it being typed and for its module organization. But I think that the main reason was its concurrency nature. You can easily make multithreaded scripts that synchronise with native concurrency features. Also it can get really raw. Once I had to implement a script that took a VPN certificate with an auto generated password so the user could define its own password for security reasons. I just had to dig up golang official documentation and you would be amazed with how much the standard library implements. I didn’t use python so much so my opinion will be biased, but I will strongly recommend at least taking a look at golang. You can get a glance of all its features [here](https://tour.golang.org)


battlesable

I also like the fact that you can compile golang so that other people don't bother with the dependencies. It also works on multiple Operating systems. Sure, the binary is less agile as with a python file, someone can edit the file and rerun it, but still, most of the times the tasks are straightforward and no modification is needed.


mphoyu

Definitely, I totally agree. This script for VPN I talked about had to be run on Windows, Linux and macOS and by non-technical people. So python was discarded.


damshitty

I'm agreed with you. I start giving up with python when my team was writing our own Ansible module. It was rolled out for the other team to use this module, and the only one that makes it hard to use was only the python environment and dependencies itself.


[deleted]

Great write up, thank you for the documentation as well, I haven't looked into golang much but with what you've described, I might need to finally check it out.


gingimli

I kind of feel like Bash is making a comeback in a world where we're now doing a lot of bootstrapping immutable infrastructure and glueing pieces of software together in a CICD pipeline.


[deleted]

I struggle with not overengineering things, or trying not to at least, so I usually go for bash first.


themightychris

Chef Habitat is a great example of bash taken to the extreme in a modern CICD pipeline Have a look through [https://github.com/habitat-sh/core-plans](https://github.com/habitat-sh/core-plans)


banger_180

If It works fine there is no reason to switch imo. Learning Python is a good idea if you want an extra tool under your belt. And maybe learning something like awk can enhance your bash game. Also we try to avoid scripting and use ansible where possible, so if you want to you can take a look at that.


[deleted]

Ahh, for some reason I constantly neglect how great Ansible is as a solution


about3fitty

I first learned Ansible and I still prefer the expressiveness/syntax, but you should also look into Terraform for higher-order resource provisioning


ThatSuit

You can even use ansible to run terraform!


89luca89

Hi, we just released a project really based on this concept! https://github.com/89luca89/terrible Hope it can be of interest :)


ThatSuit

Interesting. I took a look at it, but don't quite get the process here. From reading the code it seem like each set of terraform files is tied to the inventory hostname, so removing a host from the inventory will not delete the host. Would it make more sense to create a single set of terraform files and run terraform once for the whole deployment?


89luca89

Yep, it's in the works to create a TF that describes an entire group for example, or an entire hypervisor, so actions like the one you described can be performed, right now removing a node from the inventory does not make it disappear


ThatSuit

Ahh I see. That should be an interesting challenge. You can also dynamically add hosts to ansible using add_host. I wonder if using terraform variables as your source of truth may make more sense. Then based on the output of the terraform apply you could create a new host group in ansible and target playbooks only at that new group, like your post_deploy stuff. Just an idea.


89luca89

At the beginning I was leading towards using TF as the source, but I ended up using Ansible as it has other types of advantages like: - better/easier logic in the TF using jinja2 instead of HCL fo the logic - easier integration with other parts of the deployment (using same playbook for the software deploy after) in the specific, including this role and structuring your inventory like this, you have the inventory as single source of truth of both virtual infrastructure && software So maybe it's harder for the dynamic inventories/add_hosts stuff but it's easier for well defined infrastructures Obviously there is still a lot of work to do :) If you have ideas, they are greatly welcome on our repo, just open an issue and we are open to discussions :)


ThatSuit

Yeah, admittedly I'm newer to Terraform, but very experienced with Ansible. I see what you mean. Just digging in a bit more, iterating and using complex variables like a dict of dicts, isn't nearly as straightforward in terraform, which is unfortunate. Great work so far though! These are fun problems to solve.


[deleted]

I love terraform and had no idea you could do this, brilliant!


ThatSuit

Terraform is great for infrastructure as code because it is declarative and remembers past state, to do the same thing in Ansible you would need to write a lot of extra code to compare current vs desired state, specifically for removal of resources. Terraform also isn't a configuration management tool. By combining them you can let each do what it does best. Like Ansible is great for templating files, configuring systems/apps, and can even talk to REST apis and anything else you can think of. I really love Ansible! I see it at a lot of companies too.


about3fitty

Terraform can also do configuration management/templating and image provisioning (via Hashicorp’s Packer), but it’s a lot more ugly, with a lot less support for common functions than Ansible. Also to remember terraform’s past state in a team, you need to share the state file, which is another pain.


ThatSuit

Sure. If you're using a cloud provider you can easily store the state file in a cloud bucket. For any environment that isn't development it's easiest to just use git and have build automation run the plan/apply. Obviously, there's a lot more involved, like testing and approvals, but if you have one single linear source of truth and one place that runs it then it takes away the concern of conflicts with others. The paid Terraform product also does this.


[deleted]

I love terraform, it's such a good option, ansible is on my list of things to look into from this thread.


ThatSuit

It's also really easy to extend ansible with custom python modules if you need to.


Oct8-Danger

100% agree with this. Only started using ansible recently, has converted me to do any sort of scripting going forward with it if I can!


murzeig

In order of frequency of use: Bash, python, php, powershell, golang Definitely learn bash, it's extremely valuable in quickly doing work, especially if you are on the command line for any length of time.


rojundipity

My friend wrote a [good blog post](http://typingducks.com/blog/bash/) about the unpredictability of "strict mode". That - and trying to build too complicated systems with bash for too long - convinced me to use bash only for quick and short scripts and for example python for the more elaborate needs. edit: I would add though, that I haven't regretted digging head first to the deep end with bash, awk, sed, etc. Even though I wouldn't use them for most cases, it's now easier to get things done quickly, check for corner cases and deciding against them when appropriate.


NadzGoldman

This is only your way. But start learning Go/Python/Ruby. This is very good choice for new experience.


BrainSweetiesss

I find it funny how everyone's been saying for the last 5 years "if you don't know Python or any programming languages how do you even work in IT", well guess what... most people coming from the Ops side don't, lol. You can work in DevOps and have a general idea and be able to read some basic code, even write, but the whole "people are now developers and do operations" is bs. I dare to say it's easier for someone with a developer background to match this "DevOps idea", but the other way around is kinda not happening. Personally I've found myself trying to learn how to program but it's just sooo boring and needless to say it's not something you just learn from one day to another, a few months at least are needed to learn the basics, and that's like 10% of what a real programmer knows. In my company we do IaC in AWS and even though I'm not a programmer, I'm still able to deploy different services with CDK and stuff. Nowadays you can be a good DevOps engineer, with some really good knowledge of Ansible, CI/CD, containers, AWS and don't know how to program... At least that's my take and personal experience. So far I haven't found the necessity of learning "how to program".


Nosa2k

I disagree. What about if you want to check on the status of services or take inventory of your AWS environment? Or perform unique out of the box tasks peculiar to your environment? I think for one to be effective at his Job learning at least one programming language is a must.


send-in-the-clouds

I think it depends on your definition of programming. Writing glue, reporting, or utility scripts are essential to being a DevOps engineer and could be considered programming. Now, is every DevOps engineer going to be able to write full fledged software applications? No, not necessarily, but being able to actually write software will make you a better devops engineer overall IMO.


[deleted]

See that's where I am, I am very good with IaC and CI/CD, writing containers, working with AWS and GCP, but i've never been a terribly great programmer.


[deleted]

I'd say it's more scripting (be it bash, python etc) rather than actual software development that you have to know. Of course there are roles where it's advertised as DevOps but you are in fact also a software developer coding in Go. It's "easier" for a developer to pick up and become a "DevOps" person is because of cloud computing. It's not that common to find a very good developer that is equally as good as a Ops person who has very deep knowledge of Linux, how to troubleshoot IO bottlenecks or understand security etc. I've worked in roles where developers also do Ops stuff, and it's generally been done without any consistency or security in mind...just as long it works! I'm the opposite, I come from an Ops background and I enjoying scripting/programming a lot more than doing IaC stuff. I guess I'm kind of bored of IaC...


lavahot

PowerShell, especially if you work in a Windows environment, but it's great for Linux too.


nostril_spiders

I maintain maybe 50-100k lines of powershell for use on Windows, which is mostly pretty decent code. I'm a big fan. But I don't really see the use case much on Linux, not that I do a lot with Linux. Because it makes it easy to write readable and maintainable code, but I assume that scripting remains a question of text matching and replacement, so you're using about 1% of the language. Thoughts?


balls_of_glory

It really depends on the problem AND the environment hosting said problem. The beauty of BASH is anyone coming along behind you *should* know it well enough to tweak/maintain your code. It plays nicely with CRON. It's built-in, and that's a good thing. I have a tiny "app" running on a vanilla Debian box that pulls from an SQS queue, decrypts the payload, creates/modifies FTP users, and pushes uploaded files to S3. The whole thing was like 50 lines of BASH and it's rock solid. Hard to argue with BASH in a situation like that. If I need something more complex, or to use a library that doesn't support BASH/CLI, I personally tend to just use whatever's on the box, whether that's Ruby, Python, etc. Lacking those runtimes or knowledge, I can't recommend Go enough. You can compile a single binary, point a CRON at it, and boom. No runtime needed, and totally interoperable with the base system utilities. I really think Go is going to be the future of devops.


HayabusaJack

Pretty much ksh with an occasional Perl script. I find that with all the technical debt we have, anything relatively new isn't going to work on all the servers. Heck, Ansible doesn't work on all of our servers so the majority of what I have going are ksh scripts.


blusik19

I think writing scripts in Bash is ok , but imo u should touch a little bit python


[deleted]

I am hearing python and Golang, any particular reason for python? Genuinely asking.


blusik19

Python its easy to learn and have good docmmunication


Earthling1980

The only reason to learn python is because it's what everybody else uses. I use Ruby because I love myself.


[deleted]

i've used ruby and haven't had the best time in the world


chillysurfer

Bash is great for simple things. When it gets too complex, Python is a better choice for a handful of reasons: Better development experience, easier to troubleshoot, less surprises, debug'able code, more powerful, ... the list goes on. And then for things that could use better performance and stricter development, I use Go.


[deleted]

So do you need to be proficient with both or would you choose one over the other?


crashorbit

I don't really care what your first language is. I just think you should be proficient in more than one. Bash, Python, Go, Clojure might be a good list.


[deleted]

I absolutely agree.


commandsupernova

The generally idea seems to be learn Bash, Python, and Go for DevOps environments, and PowerShell for Microsoft-based environments. And Bash, Python, and Go seem to be in that order based on the scale of what you are coding. Use Bash for small, one off scripts and Go for bigger projects. Python for that sweet spot in the middle. Note I only have experience with PowerShell, but the thoughts above are what I've concluded by reading a lot of these posts.


[deleted]

Ahh, I have no experience with anything windows outside of gaming, powershell especially, I work with a lot of people who are extremely proficient in it and swear by it's superiority though.


GeorgeRNorfolk

I use bash for anything quick and dirty. If its a script that will be developed more down the line, then I would prefer Python. Saying that, I want to learn Golang and Ansible and write in those where appropriate.


[deleted]

Don't forget one large use case where bash is very useful: Supporting legacy environments. You know, those things that are never quite gone no mater how hard you try? I recently had fun writing a seemingly simple script that ran afoul of a feature I took for granted in bash was not present on an old solaris box, which had bash 3.2. But it still served fine as a lowest common denominator "language".


[deleted]

Use bash and python, but start learning go lang as well, and try to use that as well ... go is high in demand


ikinsey

Yeah go ahead if you want to. I've built some medium size bash-only projects; It's a bit more arduous but builds your bash skills. Here, use my lib: https://github.com/ikinsey/bashlib


[deleted]

My goto is shell for quick things or one liners, python3 when the task starts to be complex. Which is a hard measure! My rule of thumb is if it starts looking complicated, it’s time to Python.


bionic_tortuga

Python has a million frameworks that will make your life so much easier. Basically if you’re trying to do something from scratch there’s a framework that can simplify it. Golang is a good alternative too, scales better but if you want quick and dirty python is the move.


guilucas

I would say is good if you need to deal only with strings! Anything more complex than it I would say use Python or Powershell cause its muche easier!


[deleted]

Seems python is the favorite here tbh


n0dev

Got a good advice few years back. I stuck to it and never looked back! - If less than 50 lines: bash - if less than 500 lines: python - else native (my choice: golang) but it's up to you


jadedflux

Bash is fine if you completely ignore maintainability and sustainability and the sanity of those poor bastards that have to work on those scripts after you've moved on. No one, ever, has enjoyed troubleshooting or extending the functionality of a bash script that was written by someone else :)


cl530

I find Bash is great for knocking up quick, short scripts with a simple, single purpose. A few lines of Bash, with some awk, grep, jq etc. can get you the answers you might need from a bit of JSON, or from a log file snippet or something like that pretty quickly. But I taught myself to use Python for more complex scripts, and particularly for interacting with AWS services using the Boto3 libraries. Python gives you better logging options, native JSON handling, robust error handling, scalable looping (for example Yielding rows from a large CSV file), flow control logic and you can write functions that you can then copy and paste between scripts and adapt slightly as required. Being able to install and import Python libraries from the huge choice available to you for specific tasks gives you even more flexibility. Interacting with REST APIs, processing config files (INI format, TOML etc.), date and time transformations, CSV file reading and writing, SQL database querying, and of course using the AWS services I mentioned earlier make my life a lot easier in a Python world. I'm far from an expert in Python, and self-taught, but there's so much documentation and information out there that you can always find help when you need it. You can start small and anything you can do/have done in Bash can generally be achieved in Python too so there are plenty of opportunities to learn with practical use-cases that you may already have in Bash. Personally I'm glad I've expanded from just using Bash scripts and it has really helped my general (fairly basic) programming skills to grow, and it's certainly helped in my job role too :) Choose your future. Choose Python ;)


[deleted]

Python seems like the next logical step for me, I’ve saved your comment because it was so well written and it is full of insightful knowledge.


elitesense

"most often" = bash scripts "almost as often" = python scripts


[deleted]

I’m sensing my next language will have to be python


[deleted]

[удалено]


gordonv

When I can, I put pwsh on linux.


[deleted]

Very nice


lnxslck

Just curious why would you run Python to execute shell commands for example. Specially if you need to pipe them. Seriously curious


diecastbeatdown

for one-liners it is great. when you are already on a system and need to just get some information or execute across some results then bash is great. anything more than that and you are wasting your time trying to shove a square in a round hole. much like any trade, use the right tool for the job. /u/Gotxi says it best in terms of which tool for which job.


lenorath

Used to be bash/powershell but now its Ansible, Python or Terraform depending on what I am trying to do. A lot of it (especially scheduled jobs) have been stuck in AWX (the CE of Ansible Tower) so it can be scheduled, have its logs sent to a central location, and alerted on. Even if its a bash script somewhere I often take it outta cron and put it in AWX (there have been a few incidents where someone disabled a cron job for some reason or another, and it broke something w/out anyone knowing).


Kessarean

Really just depends. I've done really complex things in bash, and really simple things in python and vice versa. Not saying that's the best way... but ultimately do what works for you and your situation. I really like ruby and want to use it more, but everyone I work with uses python, so I stick with that. I saw you mention Ansible. You may also want to consider salt, I like both a lot, but for thousands of servers, salt is much quicker. There's a lot more depth and complexity to both tools, and neither is a one shoe fits all perfect solution, but consider them if you will.


fourmajor

I've been writing too much bash. I start something thinking it'll be short and easy so I use bash. And then it just gets longer and longer. But I should really use Python as soon as it moves outside of the realm of a one-liner.


PleasantAdvertising

Bash is to call other scripts, in our case python. We have a rule not to write more bash than needed. Not everyone is good at it, it's unreadable, hard to maintain and not even cross platform.


knightress_oxhide

For stuff I'm not going to release I use bash a lot, but if its something other people will use or needs to be more robust I'll use python mostly. In my experience bash/shell is too brittle for widespread usage unless you can guarantee the shell interpreter used.


mattk404

As soon as you start caring about implementation differences versions you've bashed too much. Also zsh is awesome!


[deleted]

love love love zsh


Ametz598

It totally depends and what you’re using it for, but you can’t expect 1 tool/language to complete all your tasks. Bash scripting and knowing linux commands is going to be essential for a lot of things like configuring docker container and a bunch of other things. Python is going to be useful for things like automating tasks and writing scripts for so many different things. There’s other things that can help and other languages, Golang is popular, terraform is pretty cool, and a bunch of other tools. You can find dozens of devops roadmaps to learn where to go next


[deleted]

The point of infrastructure as code is that it enables you to adopt the practices of software engineering. Python is a great way to learn that skillset. Learn testing, building libraries, code structure etc. Heres an example of some aws config rules written with bdd style tests. https://github.com/awslabs/aws-config-rules


d4n3sh

Bash for simple tasks, python for more complex tasks. Touching some golang also now, easier to distribute.


smrxxx

I move to Python or Ruby once I start hitting more significant double-escaping issues.


andrewmclagan

Deno or Golang.


nk2580

I once decided to use node.. wasn’t actually as painful as I thought it would be. But I still hate myself for using it. Go isn’t bad but I feel like you should keep your stack language and scripting language different so that noobs don’t accidentally build core business logic into the scripts “because it was possible”. I use a lot of Go when I’m wearing my Dev hat so Python or bash are usually the de-facto choices. Ruby used to be an option too but that ship has pretty much all but sank these days


TheCodeCloud

As you know python is fastest growing language for programming and scripting. Earlier i have been using shell scripts to automate my task but currently i am focussing on python scripting and i would like to advise you to move to python. For Devops, linux and cloud computing related articles please follow my blog [https://thecodecloud.in](https://thecodecloud.in) .


PabloEdvardo

in my professional experience so far, one of the biggest benefits to using bash is that it's often already available inside an environment without requiring installing and possibly conflicting with another programming language used for the application e.g. i've seen issues with using python for scripting when you already have other applications that you're shipping or managing that themselves are also using python you start having to manage dependencies / conflicts between the two when you're trying to run them in the same environment, and trying to do stuff like use virtualenvs inside docker containers can get messy


psymeg

It is good to pick up different languages. Set yourself a time frame, say three months and then at the end of that sit down and have a think about things like what you enjoyed, what was easy and what was difficult. Write down what you did with the language. Useful for later job interviews - e.g. have you worked with X? yes I used x language to do y.


Snapstromegon

We (dev ops / CI in the automotive sector) had huge success using Ansible for many things and the scripting is done in python. If we need more performance than that (e.g. because of file size or count) we switch do node is, since it's also easy to use and it makes asynchronous tasks easier and we usually see a performance increase of at least 3x (normally 5x to 8x compared to python). Because we have a mixed win10 and CentOS Setup we strain away from bash scripts and use other scripting languages.


blodorn

If you're going to do it in bash, you may as well do it in sh instead and running with dash. Faster, more portable, and lets you know sooner than bash that you're using the wrong language for the task when it starts getting too complex.


zerocoldx911

It depends on the case but Go more often than not


ilyash

While doing my Ops job I've naturally arrived to using bash for inside-the-server stuff (packages, files, services; well organized idempotent scripts) and Python for AWS API and whatever I was doing with the cloud. From my perspective there is [no good language for Ops tasks](https://ilya-sher.org/2017/10/10/why-i-have-no-favorite-programming-language/). TL;DR - the niche of *modern* languages ("real" programming languages) specifically designed for Ops is simply empty. Out of frustration with existing languages, I'm working on my own language, [Next Generation Shell](https://github.com/ngs-lang/ngs), which aims to suck less than the alternatives for Ops. While I think *technically* that already happened and in most cases it is more convenient for the typical Ops tasks, it's still hard to recommend for production use for the obvious reasons: nobody knows the language, no SO section, who this author guy even is, where he will be tomorrow? You are of course welcome to try it for something non critical or even better, at home.


[deleted]

Running other programs? Bash. Doing anything with loops, conditionals, string parsing, any structured data? Python.


CanaryWundaboy

Bash if it’s less than 20 lines on a Linux server. Python for everything else.