Skip to content
DashboardWebsite

Ansible Pack

URL slug: ansible

This page describes how the Ansible pack reads changes and groups them into analysis units. It is for engineers who review Ansible changes.

The pack reads a unified git diff and creates units for changed tasks, play-level keys and configuration hunks. Rules flag privilege, secret, hardening, performance and reliability issues.

Path globRead as
*playbook*.yml, *playbook*.yaml, *site.ymlPlaybooks: plays and their tasks
*roles/*/tasks/*.yml, *roles/*/handlers/*.ymlTask files: lists of tasks
*roles/*/defaults/*.yml, *group_vars/*, *host_vars/*Variables
*requirements.ymlGalaxy roles and collections
*ansible.cfgConfiguration

The pack also recognises Ansible by content. sniff() scores 0.8 for a root list of plays or named tasks with a module key, such as ansible.builtin.apt: or copy:. YAML with a mapping at its root scores 0.0. A root list with keys from another format, such as image, uses, run or script, also scores 0.0.

parse_diff in opentremor_pack_ansible/parser.py reads each diff hunk:

  1. It reads hunks with core’s iter_hunks from opentremor_core.libs.diff. It skips files that are neither YAML nor recognised by filename.
  2. It locates changed lines with core’s iter_yaml_blocks from opentremor_core.libs.yaml_diff. Each block gets a key path, such as ("- name: Configure web", "tasks", "- name: Install nginx", "ansible.builtin.apt").
  3. It groups blocks by their owner. The owner is the innermost task under tasks, pre_tasks, post_tasks, handlers, block, rescue or always, or a root task in a task file. A playbook change outside a task belongs to the play. Other changes are grouped into an unknown unit.
  4. It builds each task’s body from the hunk, including the context lines shown there.

Variable files, requirements.yml and ansible.cfg produce one unit per hunk. Input that is not a diff, such as a pasted playbook, is read as a new file.

Unittypename
A taskIts module, such as ansible.builtin.aptIts name:, or the module if it has no name
A play’s own keys (hosts, become, vars, roles, and others)playThe play’s first value, such as Configure web servers
A hunk of a variables filevarsThe file path
A hunk of requirements.ymlrequirementsThe file path
A hunk of ansible.cfgconfigThe file path
Changed lines whose task the hunk does not showunknownTheir key path

Added and unchanged lines determine a task’s identity. If a task changes from shell to apt, its type is apt. A deleted task is named from its removed lines. A renamed task (- name: old to - name: new) is one unit with the new name.

Markers present in the unitaction
+ onlyadd
- onlydelete
Bothmodify

The body keeps its +, - and space prefixes. Rules use these markers to distinguish a new validate_certs: false from one that was already present, or a removed checksum: from an unchanged one.

{
"hash": "<sha256 of the normalised body>",
"type": "community.general.ufw",
"name": "Allow SSH",
"action": "modify",
"body": "- - name: Allow SSH from the office network\n+ - name: Allow SSH\n community.general.ufw:\n ...",
"metadata": {
"generated_at_utc": "2026-10-26T10:30:00Z",
"source_path": "playbooks/web.yml",
"group_path": null
}
}

Rules are Markdown files in this package’s opentremor_pack_ansible/rules/ directory:

FileVariantServed at
generic-rules.mdDefault (generic)GET /v1/ansible/rules
debian-rules.mddebianGET /v1/ansible/rules?rule_type=debian
rhel-rules.mdrhelGET /v1/ansible/rules?rule_type=rhel

All three files define the same rule IDs. The variants tailor rules for OS families. The Debian rules refer to apt, ufw and the sudo group; the RHEL rules refer to dnf/yum, firewalld and the wheel group.

The pack can suggest a variant based on package modules in the input. It counts apt, apt_key, apt_repository and deb822_repository for Debian, and dnf, dnf5, yum, yum_repository and rpm_key for RHEL. The family with more matches is suggested; a tie or no matches produces no suggestion. The suggestion is shown to a person and is not applied automatically.

Rule IDAreaWhat it catches
ANS-001PrivilegeReview prompt: become: true at play level
ANS-002Privilegeshell or command built from variables
ANS-003Privilegeshell, command or raw used where a module exists
ANS-004TLSvalidate_certs: false, or removal of validate_certs: true
ANS-005Supply chainget_url without checksum, or a download piped to a shell
ANS-006SecretsA literal secret instead of a Vault or secret-manager reference
ANS-007SecretsReview prompt: a secret printed or registered without no_log
ANS-008HardeningPermitRootLogin yes or PasswordAuthentication yes
ANS-009Public exposureA firewall rule open to every source
ANS-010HardeningA world-writable mode, or a private key readable by others
ANS-011Supply chainA package repository without signing checks, or unauthenticated packages
ANS-012PrivilegeA plain-text user password, or a new account in a privileged group
ANS-013HardeningReview prompt: ignore_errors on a hardening task
ANS-014Destructivestate: absent on data, or rm -rf on a variable path
ANS-015Supply chainAn unpinned Galaxy role or collection, a branch pin, or a new source
ANS-PERF-001 to -004PerformanceA package module in a loop, a long task without async, unused fact gathering, or increased fan-out
ANS-REL-001 to -005ReliabilityConfig written without validate:, restart without serial, restart outside a handler, command or shell without idempotency controls, or max_fail_percentage removed

Performance and Reliability rules have LOW or MEDIUM severity. They appear in the review but do not fail the merge check on their own. Core keeps an organization’s unedited rows in step with these files (OpenTremor-core#0034).

diff --git a/playbooks/web.yml b/playbooks/web.yml
--- a/playbooks/web.yml
+++ b/playbooks/web.yml
@@ -24,5 +19,5 @@
- name: Fetch the app release
ansible.builtin.get_url:
url: https://releases.example.com/app-1.4.2.tar.gz
dest: /opt/app/app.tar.gz
- checksum: "sha256:9f2c4e1d..."
+ validate_certs: false

The pack creates one unit: type ansible.builtin.get_url, name Fetch the app release, action modify. The LLM can match ANS-004 to the added validate_certs: false and ANS-005 to the removed checksum.

The pack’s demo sample in opentremor_pack_ansible/demo/ includes this change and four others from the same playbook.