このコンテンツは選択した言語では利用できません。

Chapter 5. Validate and debug content with the AI assistant


Use the AI assistant to validate playbooks in real time, identify issues before execution, and automatically apply fixes.

5.1. Prerequisites

  • VS Code is open with the Ansible VS Code extension active.
  • The Ansible MCP Server is enabled.
  • An Ansible playbook open in the VS Code editor.

5.2. Validate content with the AI assistant

Ask the AI assistant to analyze the current playbook without modifying it. This identifies specific rule violations and potential errors. If errors are found, ansible_lint has autofix functionality, enabling it to suggest changes, and, with your permission, implement those changes in your code.

Procedure

  1. Open the playbook file in the VS Code editor.
  2. Open the Copilot chat window.
  3. In the chat window, enter a natural language prompt such as:

    • Validate my webserver playbook to check for any issues.

      This triggers the ansible-lint tool in check-only mode. The assistant displays a list of the issues it found, including Rule IDs, line numbers, and descriptions of the errors (for example, missing FQCN, or YAML formatting issues).

      The assistant will ask "Would you like ansible-lint to apply automatic fixes?” You must grant the AI assistant permission to make any changes to your code.

  4. Enter “yes” or “no” depending on whether you want the assistant to apply the suggested changes.
  5. Select the option to allow or skip to grant the assistant permission to make changes.

    1. If you select allow, the AI assistant will update your code.
    2. If you select skip, the AI assistant will output a list of issues and the suggested fix for each.

5.3. Auto-fixing errors with the AI assistant

You can also prompt the AI assistant to automatically fix errors that ansible_lint finds.

Procedure

  1. In the GitHub Copilot chat window, enter the following prompt:

    • Run ansible-lint on my webserver playbook and apply automatic fixes.

      The automated workflow triggers the ansible_lint tool with the fix: true parameter.

  2. The ansible_lint tool then processes the file and applies corrections for issues such as:

    • Converting short module names to fully qualified ones.
    • Correcting YAML indentation and Jinja2 expression spacing.
    • Fixing key ordering within tasks.

Verification

When the AI assistant completes the auto fixes, confirm the updates by taking the following steps.

  • Either verify in the chat window that the AI assistant has displayed the fixed content, or confirm that the file has been updated.
  • Review your open file in the editor. Changes (such as updated module names) should be reflected immediately in the code.

5.4. Debug with the AI assistant

You can ask the AI assistant to analyze a playbook to identify why it is failing, or to find potential bugs.

Procedure

  1. Open the playbook that you want to debug.
  2. In the GitHub Copilot chat window, enter a natural language prompt describing the situation. For example:

    • Analyze this playbook and explain why it might be failing.
    • Run debugging analysis on this file.

      The AI assistant uses its embedded tools (such as static code analysis) to scan the playbook for common errors, logic gaps, or configuration mismatches.

      The assistant then provides an explanation of the issue in natural language, translating technical error codes or anti-patterns into understandable and actionable information.

5.5. Implement fixes with the AI assistant

After the AI assistant has generated a list of fixes, you can ask the assistant to help you implement those fixes.

Procedure

  1. Review the assistant’s response. It should highlight sections of the code that have errors or that could be improved.

    The analysis might include:

    • Identification of Anti-patterns: Flagging inefficient or insecure practices.
    • Failure Analysis: Explaining logical errors that could cause runtime failures.
    • Best Practice Gaps: Noting where the code deviates from the "prescriptive rule sets" derived from Ansible content best practices.
  2. Prompt the assistant to provide a solution. For example:

    • How do I fix this error?
    • Refactor this task to follow best practices.

      The assistant generates a corrected code block, ensuring that it adheres to best practice recommendations (such as correct indentation, valid parameters, and proper module usage).

Next steps

After applying the suggested changes, verify that there are no further issues.

  1. Apply the changes to your playbook.
  2. (Optional) Ask the assistant to confirm the new structure. For example, you can ask Does this look correct now?

    The assistant might trigger ansible_lint again or perform a final static check to ensure the debugging session resolved the issues.

Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2026 Red Hat
トップに戻る