Building reusable automation with IBM watsonx Code Assistant

15 May 2025

Author

Nicole Smith

Product Marketing Manager, IBM Watsonx Code Assistant

In today’s rapidly evolving digital landscape, automation is no longer a luxury—it’s a strategic imperative. Forward-thinking IT leaders are reimagining operations by embedding intelligence and repeatability into every layer of infrastructure. As organizations strive to build more resilient and adaptive systems, the ability to generate modular, reusable automation assets becomes a key differentiator in achieving long-term agility and success.

With the latest feature of IBM watsonx Code Assistant—Ansible Role generation—creating reusable automation has never been easier.

Understanding Ansible roles

Ansible Roles are a powerful way to organize and distribute automation tasks. They encapsulate tasks, handlers, variables and other components into reusable units, making it easier to manage and maintain complex automation scripts. But why are Ansible Roles so crucial?

  • Modularity: Imagine trying to manage a sprawling automation script with hundreds of lines of code. It would be a nightmare to maintain and debug. Ansible Roles allow you to break down these complex tasks into smaller, manageable pieces. This modularity simplifies the development and maintenance of automation scripts, making your life much easier.
  • Reusability: One of the biggest advantages of Ansible Roles is their reusability. Roles can be shared and reused across different projects and environments. This not only reduces duplication of effort but also ensures consistency in automation practices. Once you've created a role, you can use it in multiple playbooks, saving time and effort.
  • Maintainability: Keeping automation scripts up-to-date can be a daunting task, especially in dynamic IT environments. Ansible Roles make this process much more manageable. When your automation is organized into roles, you can make changes in one place and propagate them across all instances where the role is used. This centralized approach to maintenance ensures that your automation scripts remain consistent and reliable.

Technical impact of Ansible Role generation

Let’s take a look at a real-world example with IBM’s CIO organization.

The Chief Information Officer (CIO) Organization leads IBM’s internal IT strategy and is responsible for delivering, securing, modernizing and supporting the IT solutions that IBM, clients and partners rely on every day. The CIO team has been using watsonx Code Assistant with strong results, and recently began leveraging its Ansible Role Generation feature to further democratize development, accelerate onboarding, and boost productivity.

This feature empowers developers—including those with less experience—to generate standardized, best-practice-aligned code with minimal manual intervention. What did the stakeholders have to say?

  • Robert Barron, an architect in cloud platform engineering, noted the tool’s evolution from producing basic functional code to generating robust, Red Hat-compliant roles that are reliable, reusable and maintainable.
  • Rick Goncalves, an automation architect and SRE, emphasized how the tool streamlines development by organizing code structures and reducing time spent on manual setup. The explanation feature has also proven invaluable, offering detailed insights into generated code, including prerequisites and dependencies—an asset for onboarding junior developers.
  • Raj Singh, an automation developer and SRE, and Hamid Qurbani, software engineer both shared how the tool has accelerated learning for new team members, enabling them to reverse-engineer Ansible code and build confidence through hands-on experience. In real-world use, the tool has been applied to projects like IBM MQ service automation, demonstrating its ability to generate functional code out-of-the-box.
  • Rodolfo Ferraz Nogueira, a senior technical support analyst, used role generation for z/OS tasks such as JCL job creation and praised the intuitive interface and the clarity of the explanation feature when working with standard Linux playbooks.
  • Bruno Luiz Bertozzo de Almeida Arruda, a software developer, highlighted the tool’s growing accuracy in generating PowerShell scripts for Windows server patching, while Bianca Gusmao Cordebello, software developer, noted how the explanation feature helped new developers quickly understand and adapt code, reducing the need for manual corrections and accelerating productivity.

Getting started with watsonx Code Assistant and Ansible Roles

The first step is to install IBM watsonx Code Assistant. You can do this by downloading and connecting your Ansible VS Code extension directly in your IDE and click “Generate an Ansible Role” to get started with role generation.

Creating your first role:

  1. Open the Ansible menu from VS Code’s Activity bar.
  2. Navigate to role generation: Select the option for Ansible Role generation from the main menu.
  3. Define your role: Use natural language to describe the role you want to create. For example, you might say, "Create a role to install and configure Apache."
  4. Receive role outline: Watsonx Code Assistant will provide an outline of the role based on your description. This outline includes directories for tasks, handlers, variables, templates, and files.
  5. Review: Edit the outline as needed
  6. Create: Choose the collection where you want to create the role. You must have a collection inside your workspace to create a role.
  7. Save: Click Save files. A list of files is displayed that includes the new role.

By using watsonx Code Assistant, integrating roles into your Ansible Playbooks is streamlined and efficient, making automation easier than ever. The role generation features allow you to create roles using natural language, simplifying the setup and reducing the time required to organize and manage your automation tasks. Once generated, these roles can be effortlessly integrated into your Ansible playbooks, leveraging their modularity and reusability to enhance your automation scripts.

As you continue to explore and expand your automation capabilities with watsonx Code Assistant, you'll be well-equipped to tackle increasingly complex challenges and streamline your workflows.

Visit the watsonx Code Assistant 

The latest product news from IBM

Get the biggest product and feature announcements, including recent video chats on products, and educational offerings from IBM and our training partners. See the IBM Privacy Statement.

Thank you! You are subscribed.