Instruction file imported from zjleblanc/zjleblanc.utils (
.cursor/rules/ansible-standards.mdc). Copyright stays with the author.
description: Standards for Ansible collections, roles, and playbooks to ensure best practices and ansible-lint compliance. globs: "**/*.{yml,yaml}", "galaxy.yml", "meta/runtime.yml" alwaysApply: false
Ansible Standards
Best Practices
Role Variables
Variables registered within a role MUST be prefixed with the role name to avoid namespace collisions and comply with var-naming[no-role-prefix].
# ❌ BAD
- name: Check status
ansible.builtin.command: check_status
register: r_status
# ✅ GOOD
- name: Check status
ansible.builtin.command: check_status
register: my_role_status
Collection Versions
- In
galaxy.yml, usesemantic_versionas a placeholder for CI-driven versioning. - Always configure
.ansible-lintto skipgalaxy[version]andschema[galaxy]when using this placeholder. - Enable
offline: truein.ansible-lintto prevent fatal errors during dependency resolution in restricted environments.
Supported Versions
- Ensure
meta/runtime.ymlspecifies a currently supported Ansible version (e.g.,>=2.15.0). - Role metadata in
meta/main.ymlshould use quoted strings formin_ansible_version.
# ✅ GOOD (meta/main.yml)
galaxy_info:
min_ansible_version: "2.15.0"
Formatting
- No trailing spaces in YAML files.
- Always include a newline at the end of files.
- Use proper Jinja2 spacing:
{{ variable | filter }}.
