ansible-testing
БесплатноБез исполняемых скриптовНе проверенTesting strategies and ansible-lint configuration for validating Ansible automation quality, covering lint rules, syntax validation, and integration test setup.
Об этом скилле
Ansible Testing
Testing strategies and ansible-lint configuration for Ansible automation.
ansible-lint
Running Lint
# Via mise (recommended)
mise run ansible-lint
# Directly with uv
uv run ansible-lint ansible/playbooks/
# Specific file
uv run ansible-lint ansible/playbooks/my-playbook.yml
# With verbose output
uv run ansible-lint -v ansible/
Configuration File
Located at ansible/.ansible-lint:
---
# Profile: null, min, basic, moderate, safety, shared, production
profile: moderate
# Offline mode - don't download Galaxy requirements
offline: true
# Exclude paths
exclude_paths:
- .cache/
- .venv/
- .git/
- "*/templates/"
- "*.j2"
- .deprecated/
# Rules to skip completely
skip_list:
- var-naming[no-role-prefix] # We use descriptive names
- run-once[task] # Safe with our strategy
- command-instead-of-module # CLI tools require command
- yaml[line-length] # Long lines in infra configs
# Rules to warn but not fail
warn_list:
- fqcn[action-core]
- fqcn[action]
- no-handler
- name[play]
Common Rule Categories
| Category | Description |
|---|---|
fqcn |
Fully qualified collection names |
yaml |
YAML formatting (indentation, line length) |
name |
Task/play naming conventions |
command-instead-of-module |
Using command when module exists |
no-changed-when |
Missing changed_when on command |
risky-file-permissions |
Missing explicit file permissions |
Fixing Common Issues
Missing name on task:
# BAD
- ansible.builtin.apt:
name: nginx
# GOOD
- name: Install nginx
ansible.builtin.apt:
name: nginx
Short module name:
# BAD (triggers fqcn warning)
- name: Install package
apt:
name: nginx
# GOOD
- name: Install package
ansible.builtin.apt:
name: nginx
Using shell instead of command:
# BAD (when no shell features needed)
- name: List files
ansible.builtin.shell: ls -la /tmp
# GOOD
- name: List files
ansible.builtin.command: ls -la /tmp
changed_when: false
Missing changed_when:
# BAD (always shows changed)
- name: Check status
ansible.builtin.command: systemctl status app
# GOOD
- name: Check status
ansible.builtin.command: systemctl status app
register: status_check
changed_when: false
failed_when: false
Syntax Checking
Validate playbook syntax before running:
# Check syntax only
uv run ansible-playbook --syntax-check playbooks/my-playbook.yml
# Check mode (dry run)
uv run ansible-playbook playbooks/my-playbook.yml --check
# Diff mode (show changes)
uv run ansible-playbook playbooks/my-playbook.yml --check --diff
Idempotency Testing
Verify playbooks are idempotent by running twice:
# First run - may show changes
uv run ansible-playbook playbooks/setup.yml
# Second run - should show 0 changes
uv run ansible-playbook playbooks/setup.yml
# If second run shows changes, playbook is NOT idempotent
Automated Idempotency Check
#!/bin/bash
set -euo pipefail
PLAYBOOK="$1"
echo "First run..."
uv run ansible-playbook "$PLAYBOOK"
echo "Second run (checking idempotency)..."
OUTPUT=$(uv run ansible-playbook "$PLAYBOOK" 2>&1)
if echo "$OUTPUT" | grep -q "changed=0"; then
echo "✓ Playbook is idempotent"
exit 0
else
echo "✗ Playbook is NOT idempotent"
echo "$OUTPUT" | grep -E "(changed|failed)="
exit 1
fi
Integration Testing
Test Against Real Infrastructure
# Limit to test hosts
uv run ansible-playbook playbooks/deploy.yml --limit test_hosts
# With verbose output
uv run ansible-playbook playbooks/deploy.yml --limit test_hosts -vv
Pre-flight Validation
Add validation tasks at playbook start:
---
- name: Deploy with validation
hosts: all
become: true
pre_tasks:
- name: Validate target environment
ansible.builtin.assert:
that:
- ansible_distribution == "Debian"
- ansible_distribution_major_version | int >= 11
fail_msg: "Requires Debian 11+"
- name: Check connectivity
ansible.builtin.ping:
- name: Verify disk space
ansible.builtin.assert:
that:
- ansible_mounts | selectattr('mount', 'equalto', '/') | map(attribute='size_available') | first > 1073741824
fail_msg: "Insufficient disk space"
Test Playbook Pattern
Create test playbooks for validation:
# playbooks/test-role.yml
---
- name: Test role functionality
hosts: test_hosts
become: true
vars:
test_mode: true
roles:
- role: my_role
tasks:
- name: Verify service is running
ansible.builtin.systemd:
name: myservice
register: service_status
failed_when: service_status.status.ActiveState != "active"
- name: Verify config file exists
ansible.builtin.stat:
path: /etc/myservice/config.yml
register: config_stat
failed_when:
Установить ansible-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл ansible-testing?
Testing strategies and ansible-lint configuration for validating Ansible automation quality, covering lint rules, syntax validation, and integration test setup.
Как установить скилл ansible-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл ansible-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic