Generative AI Tools for Infrastructure as Code
Infrastructure as Code (IaC) helps DevOps, ITOps and other engineers manage data, applications and infrastructure in dynamic IT environments with increasing scale, complexity and diversity. With a GitOps-driven workflow, engineers can bring much-needed standardization, security and operational consistency across diverse environments.
While there are many compelling reasons to embrace IaC, one innovation tips the scales in its favor: generative artificial intelligence (AI). Only a year ago, there was a lot of skepticism about the accuracy of AI-generated code. But the technology is evolving rapidly, such that it’s becoming a key enabler for IaC and transforming from a best practice into an indispensable strategy.
OpenAI has been leading the industry with generative AI tools such as ChatGPT, but many broad generative AI capabilities are possible with other capable large language models (LLMs) like LLAMA by Meta. My colleagues at Dell have published a white paper on building general-purpose LLM environments.
There are many generative AI tools available that can help you accelerate your workflows, your learning and even your career. I’ll describe some of these capabilities here.
If I had to choose between paying for a monthly haircut or a generative code assistant subscription, I would choose the latter. Tools like GitHub Copilot are now indispensable — even if you’re only doing shell scripting, let alone writing elaborate Ansible playbooks. These tools reduce the time it takes to create the building blocks of code necessary for automating tasks, and every line of generated code includes a meaningful comment that your high school English teacher would approve. My Ansible for OpenManage Enterprise video shows many examples of how these tools can help you generate code.
Generative AI models can parse through and interpret code written in a wide variety of programming languages, thanks to their extensive training with millions of lines of code. When you need to interpret code, for example when refactoring code or trying to improve existing automation scripts, prompting the LLM with code can be easier than using plain English. Here is a quick example where I generate the Ansible equivalent of a good, old shell script using the latest ChatGPT 4 model.
My shell script input to create a compressed backup of a folder:
The initial Ansible output:
When I prompted the model for a more structured code block with variables, it returned:
The latest ChatGPT interface supports attaching files so you don’t have to copy and paste code you need to refactor. Just organize the files and attach them to your prompt.
Error Analysis and Debugging
If you think copying and pasting error messages into Stack Overflow is the best way to debug code, think again. LLM-based code interpreter tools can analyze error messages and logs and, in many cases, identify the root causes of frequently occurring issues. This applies to any code, including Ansible playbooks and Terraform modules where an LLM can swiftly recommend fixes, link to the relevant documentation or possibly even automate the resolution process.
Writing prompts has become a critical skill in determining an LLM’s response accuracy. The more specific and detailed your prompt, the more usable the response. Here are some IaC examples:
“I am working on a Terraform project where I need to provision an AWS EC2 instance with specific requirements: It should be of type ‘t2.micro’ within the ‘us-east-1’ region and include tags for ‘Name’ as ‘MyInstance’ and ‘Environment’ as ‘Development’. Could you provide me with the Terraform code snippet that defines this resource?”
“I need to create an Ansible playbook that performs a common operation: updating all packages on a group of Ubuntu servers. The playbook should be idempotent and only target servers in the ‘webservers’ group. It must also restart the ‘nginx’ service only if the updates require a restart. Can you generate the YAML code for this playbook?”
And if you are on a mission to change the world with automation, try something like this:
“For my automation scripts using Python in a DevOps context, I require a robust error handling strategy that logs errors to a file and sends an email notification when a critical failure occurs. The script is meant to automate the deployment process. Could you provide a Python code sample that demonstrates this error handling?”
Given these powerful capabilities, please let a code assistant help you, even if you have to skip a few coffees or a haircut.
Create Your Own GPT (Global Project Tool)
If you already have a ChatGPT tab open in your browser all the time and have become a prompt-writing expert, there is more you can do with generative AI than just generating code.
Thanks to recently announced GPT models and OpenAI’s Assistants API, you can create a tailor-built model that is faster and more precise in its responses. You can train GPT models with anything, such as a policy document or coding guidelines or an IT infrastructure-size calculator, and have chatbots use these backend models to answer queries from customers or internal stakeholders. (Please note that there are costs associated with these capabilities, depending on the number of clients and usage.)
Key elements in a custom GPT:
Code interpreter: This is not much different from the coding capabilities in ChatGPT or GitHub Copilot. When creating a custom GPT, include an option where the user can select whether they want the code interpreter to be used. This is because of the Assistants API’s pay-for-what-you-use pricing model; users who do not need this capability can uncheck it.
Knowledge retrieval: AI-powered knowledge-retrieval systems can instantly pull up relevant technical documentation and best practices that are pertinent to the task at hand, whether it is crafting an Ansible playbook or defining resources in Terraform. This immediate access to information accelerates the development process and helps with maintaining industry standards across platforms.
Your own functions: If you have already built scripts and routines to compute things or make decisions, you can incorporate them into your custom GPT. I recently saw an example where a return on investment (ROI) calculator was incorporated into a chatbot to help website visitors evaluate the benefits of switching to solar power. You could create a sizer or performance benchmarking tool for your target end user.
A Note of Caution about Proprietary and Sensitive Data
While LLMs are the best thing to happen to programmers in a long time, exercise extreme caution when training AI models using data that is not publicly available. Depending on the use case, put extensive guardrails in place when using sensitive or proprietary data in your prompts or knowledge documents that you use for training. If your organization doesn’t have such guardrails, you can be a champion to create them and be a part of the process to help your organization achieve greater AI adoption maturity.
Dell has been at the forefront as the leading AI infrastructure provider for the enterprise. Here are some other resources to learn more about setting up your infrastructure for LLM training:
- AI at Dell Technologies, including an insightful talk by CTO John Roese
- Dell and Meta Collaborate to Drive Generative AI Innovation
- Llama 2: Inferencing on a Single GPU (Graphical Processing Unit)
- Generative AI in the Enterprise — Inferencing