Putting GenAI to Work in DevOps: A Practical Guide

The emergence several years ago of generative AI software engineering tools, such as GitHub Copilot, spawned tremendous speculation about how the DevOps teams of the future would leverage AI to accelerate workflows and gain efficiency.

Now, more than three years after genAI exploded onto most DevOps practitioners’ radar screens, the days of speculation are over, and the era of real-world AI use for DevOps has begun. A mid-2024 survey found that 20 percent of DevOps professionals were already using AI across all stages of the software delivery process, a figure that is bound to grow in coming years.

This means that DevOps engineers who are not yet using AI – or who are using it, but only in a limited capacity – now find themselves facing a pressing question: How can they employ generative AI technology on a practical, day-to-day basis to do their jobs better?

I have some thoughts on the answer. As someone who is already putting genAI to extensive use to support DevOps workflows (both for my own projects, and as part of my consulting work with DevOps teams at external organizations), I know what it looks like to apply genAI to DevOps in practice, not just in theory.

Read on for takeaways regarding what I’ve learned about using AI for DevOps, and how I think DevOps engineers can best optimize their application of AI tools.

How AI can benefit DevOps

Let me begin by discussing why DevOps teams not only stand to benefit from AI, but absolutely need to embrace AI if they want to work as efficiently and innovatively as possible.

The reason is that, put simply, generative AI can dramatically accelerate many of the core tasks within DevOps workflows. In addition to writing pretty good code in a fraction of the time it would take engineers to develop the same code from scratch, AI can also generate test cases to support software testing initiatives (and, in so doing, extend testing code coverage). It can produce explanations of how code works, helping engineers digest the inner-workings of code written by others more quickly. It can automatically suggest updated code to fix bugs, saving engineers from having to scrutinize broken code and come up with a remediation on their own.

None of these are things that DevOps engineers couldn’t do without help from AI. But AI allows them to complete these tasks much faster than they could if they did things the “old” way – by hand.

Applying AI to DevOps: Real-world examples

To illustrate exactly how DevOps teams can and are using AI today, here are some real-world examples drawn from my own experience.

  1. Working with S3 and Terraform

I wanted to establish an Amazon S3 backend for Terraform. I asked an AI tool to write a Bash script for this purpose. (My preferred tool is Cursor, although there are many other great options out there – and given the speed at which the AI-assisted coding space is evolving, it’s a safe bet that we’ll continue to see excellent code generation tools emerge.) The results were perfect; the script worked flawlessly.

Originally, the script used environment variables to manage access credentials. I wanted to switch to profiles, so I asked the AI tool to update the script. Here again, the results were perfect.

The final update was asking AI to modify the script so that it would accept the profile as a command argument instead of having to set it as an environment variable. Here, I had to make a minor tweak by changing two characters in the AI-generated code to make things work – so this endeavor ultimately required a small amount of manual effort, but it took much less time than I would have needed to create this script from scratch.

  • Working with CloudTrail and SNS

I needed to generate Terraform code to generate notifications using Amazon’s Simple Notification Service (SNS) and CloudTrail. The AI results were nearly flawless, but there was a small error involving a hardcoded value. I had to turn it into a variable to make the code work. Here again, though, AI saved substantial time and effort.

  • Marshaling Go structs

To generate a function that converts JSON strings and marshals them into Go structs, I issued this directive to AI:

Write a function that converts a json string and marshals it into go structs. An example json string is ###Sample JSON scrubbed###

In this case, the results were perfect on the first try. Writing this type of function from scratch would have taken probably a hundred times longer than verbalizing the AI instructions.

Best practices for using AI in DevOps

While AI opens the door to tremendous opportunity and innovation in DevOps, it comes with a learning curve. DevOps engineers must take deliberate steps as they learn to integrate AI into their workflows.

  • Verbalize questions and tasks

To use genAI effectively in DevOps, engineers must learn to verbalize questions and tasks. Verbalization means describing in natural language what code should do (either by typing out instructions or speaking them verbally into an AI tool with speech-to-text capabilities). It’s a distinct skill from typing out code, which is the way DevOps engineers have traditionally approached the task of telling computers what to do.

There is no “one dumb trick” to learning to verbalize AI instructions quickly. The best strategy is to experiment with different prompts, compare the results and take note of which descriptions yield the best code. Personally, I like to think of records of AI inputs and outputs as an “AI diary,” which I review periodically to assess which of my prompts work best and where I commonly fall short.

  • Recognize errors in AI-generated code

Generative AI is impressively good at generating code, but like humans, it’s not perfect. Learning to identify and correct its errors is paramount for using AI effectively in DevOps.

A challenge here is that, unlike humans, AI can’t tip you off to parts of its code that might be messy or broken. When a human programs, he or she can tell which code is most likely to be buggy because human programmers know which code is toughest for them to write. But AI simply spits out code and leaves it to you – the DevOps engineer – to determine whether it can be trusted.

There are two ways to help find AI’s errors. One is software testing – which you should do thoroughly with both human-generated and AI-generated code, but which becomes extra important when handling the latter. The other is to learn from experience over time which types of code AI is most likely to struggle with. AI tools are more adept at some coding tasks and programming languages than others, and as DevOps teams integrate AI into their workflows, they’ll start to gain a sense of where AI most commonly makes mistakes.

  • Update the software development life cycle

Traditionally, DevOps teams have operated according to the principles of the software development life cycle (SDLC), which breaks the development process into several distinct phases – design, implementation, building, testing and so on.

The SDLC doesn’t change fundamentally when DevOps engineers leverage AI tools. But it does require some modifications, particularly in the code implementation phase. There, developers must add sub-steps to their processes to cover the tasks of issuing prompts to AI tools and evaluating the code they produce prior to merging it into a codebase.

  • Embrace the genAI learning curve

GenAI comes with a learning curve. In the short term, integrating genAI into DevOps processes may lead to workflows that take longer to complete than they did without AI, simply because engineers have yet to learn how to use the AI as effectively as possible.

DevOps teams must resist the temptation to stick with the old way of doing things just because it’s faster in the short term. Once they conquer the AI learning curve, they’ll enjoy dramatic efficiency gains – but it can be easy to lose sight of that goal when you’re finding it hard to complete a particular task with AI and you already know how to complete the task using another approach.

The question facing most DevOps teams is now whether they should adopt AI. It’s how they can adopt it, and how they can maximize its value once it becomes a part of their workflows. Making the shift is a process that requires significant investment of time and effort. But once you’re there, you’ll likely find that AI helps to double-down on the innovations and efficiencies at the core of DevOps by helping teams deliver software faster and more smoothly than ever.

By Derek Ashmore