このコンテンツは選択した言語では利用できません。
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
- Open the playbook file in the VS Code editor.
- Open the Copilot chat window.
In the chat window, enter a natural language prompt such as:
Validate my webserver playbook to check for any issues.
This triggers the
ansible-linttool 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.
- Enter “yes” or “no” depending on whether you want the assistant to apply the suggested changes.
Select the option to allow or skip to grant the assistant permission to make changes.
- If you select allow, the AI assistant will update your code.
- 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
In the GitHub Copilot chat window, enter the following prompt:
Run
ansible-linton my webserver playbook and apply automatic fixes.The automated workflow triggers the
ansible_linttool with thefix: trueparameter.
The
ansible_linttool 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
- Open the playbook that you want to debug.
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
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.
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.
- Apply the changes to your playbook.
(Optional) Ask the assistant to confirm the new structure. For example, you can ask Does this look correct now?
The assistant might trigger
ansible_lintagain or perform a final static check to ensure the debugging session resolved the issues.