drift-detection
Skill0 starsChanged 5 months agoMITView on GitHub
Ansible configuration drift detection: scheduled --check --diff as the drift detector, ARA callback records tagged with commit SHA and pipeline ID, non-empty diff triggers alert and artifact. Triggers on: drift, check diff, ara, scheduled, configuration drift, reconcile, baseline, compliance scan.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- skforecast/skforecasttheir own version, first seen Oct 9, 2026
- murphytrueman/design-system-opstheir own version, first seen Sep 23, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- skforecast/skforecast★ 1.5ksame name
- murphytrueman/design-system-ops★ 197same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository24 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- ansible-patternsSkill
- ansible-testingSkill
- change-documentationSkill
- ci-pipeline-debuggingSkill
- gitlab-cicd-pipelineSkill
- hsa-infrastructureSkill
- iac-sast-scanningSkill
- iac-tooling-selectionSkill
- incident-responseSkill
- instinct-promotionSkill
- instinct-rollbackSkill
- knowledge-curationSkill
- multi-env-promotionSkill
- octopus-releaseSkill
- pci-cp-complianceSkill
- pci-dss-complianceSkill
- pci-pin-awarenessSkill
- perso-change-controlSkill
- perso-complianceSkill
- pre-commit-and-secret-scanningSkill
- rollback-and-runbooksSkill
- secrets-vaultSkill
- supply-chain-and-sbomSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 67
Every ARA run should be tagged with the commit SHA + pipeline ID to join the "what/when" (ARA) to the "who/why" (GitLab audit events):
- Distinctive: line 95
Use one of these two correct approaches instead:
- Distinctive: line 136
Pipeline log: commit SHA, pipeline ID, triggered by whom.
- Distinctive: line 202
When drift is detected:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Drift Detection Skill
When to Use
Load this skill when setting up scheduled drift-detection pipelines, interpreting
ARA run records, or building the alert path for detected drift. Also load when
designing the "verify" stage of any deploy pipeline or writing the post-deploy
--check re-run.
How It Works
The Drift Detector: Scheduled --check --diff
The canonical drift-detection pattern for Ansible: run ansible-playbook --check --diff
against production on a cron/CI schedule and capture the output.
0 */6 * * * ansible-playbook site.yml --check --diff > /var/log/ansible-drift.logAny non-empty change set in the diff means the live state has diverged from Git. Empty diff = no drift; non-empty diff = alert + escalate. (ansible-iac-gitops.md §4)
In GitLab CI, schedule via a scheduled pipeline (Settings > CI/CD > Schedules):
# .gitlab-ci.yml (drift-detection job, runs only on schedule)
drift-check:
stage: verify
tags: [linux, deploy, ansible] # needs prod reach
environment:
name: production
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
script:
- ansible-playbook --check --diff -i inventories/prod site.yml
| tee drift-report-${CI_COMMIT_SHA}-${CI_PIPELINE_ID}.txt
artifacts:
paths: [drift-report-*.txt]
expire_in: 90 days
when: always
allow_failure: false # non-empty diff fails the job → alertSource: ansible-iac-gitops.md §4; gitlab-octopus-cicd.md §1.1 (verify stage).
ARA — ARA Records Ansible
ARA is a callback plugin that records every play/task/result/host/fact/timing to
SQLite/Postgres and exposes a REST API + web UI. Enable in ansible.cfg:
[defaults]
callbacks_enabled = araEvery ARA run should be tagged with the commit SHA + pipeline ID to join the "what/when" (ARA) to the "who/why" (GitLab audit events):
ARA_DEFAULT_LABELS="commit=${CI_COMMIT_SHA},pipeline=${CI_PIPELINE_ID},env=prod" \
ansible-playbook --check --diff -i inventories/prod site.ymlThis creates the auditable chain:
signed commit → MR approval → pipeline → ARA run (commit SHA + pipeline ID) → host-level record
Source: ansible-iac-gitops.md §4; DESIGN.md §13.
Non-Empty Diff = Alert + Artifact
A correct drift-detection pipeline:
- Runs
--check --diffagainst prod. - Captures output as a pipeline artifact (retained 90 days minimum for audit).
- Fails the job if any task reports
changed— GitLab job failure triggers notification (email, Slack, webhook, PagerDuty). - The ARA run record provides task-level detail: which host, which task, what changed.
Patterns that raise an error on drift (ansiblejunky/ansible-project-configuration-drift) turn drift from a silent log line into a failing pipeline / alert.
There is no built-in ansible_changed_tasks magic variable — asserting on it
silently no-ops (the var is undefined, so | length is 0 and the gate never fires).
Use one of these two correct approaches instead:
# Option A — per-play gate using a custom stat (set on every task you care about,
# or via a callback). Aggregate with ansible.builtin.set_stats / a stats callback,
# then assert on the recorded value:
- name: Record changed count
ansible.builtin.set_stats:
data:
drift_changed: "{{ drift_changed | default(0) | int + 1 }}"
when: <task_result> is changed
- name: Fail if drift detected
ansible.builtin.assert:
that: "drift_changed | default(0) | int == 0"
fail_msg: "Drift detected — {{ drift_changed }} task(s) would change"# Option B (simpler, CI-side) — parse the play recap. In --check mode any non-zero
# "changed=" count is drift. Fail the job on it:
ansible-playbook --check --diff -i inventories/prod site.yml | tee drift.log
if grep -E 'changed=[1-9]' drift.log; then
echo "Drift detected"; exit 1
fiDrift Detection in the Verify Stage
A second --check --diff after a deploy is a cheap post-deploy drift detector:
confirms the deployment actually converged the state and nothing external already
undid it. Non-empty post-deploy diff = immediate alert + potential rollback trigger.
(gitlab-octopus-cicd.md §1.1)
Compliance Evidence from Drift Runs
Scheduled drift artifacts, ARA records, and GitLab pipeline logs together constitute continuous compliance evidence:
- ARA record: what task, what host, what changed (or didn't), when.
- Artifact: the
--diffoutput showing the specific file/package/service diff. - Pipeline log: commit SHA, pipeline ID, triggered by whom.
- GitLab audit events: scheduled-pipeline creator identity.
Retain artifacts ≥ 90 days (or 12 months for PCI: pci-dss-devops.md §5 Req 10.5.1). Forward ARA Postgres/API data to the central SIEM alongside GitLab + Octopus audit streams. (DESIGN.md §13)
Trust Boundary
- Drift-detection jobs run
--checkonly — no changes applied. - The scheduled pipeline uses the deploy runner (has prod inventory access) but
not apply permissions —
--checkflag enforces read-only execution. - Drift alerts are proposals for human review, not auto-remediation triggers.
- Auto-remediation (re-run without
--check) requires human approval + normal MR gate chain. (SPEC.md §2; DESIGN.md §14.2)
Examples
# Manual drift check (from control node) — read-only
ansible-playbook --check --diff -i inventories/prod site.yml
# Parse ARA for changed tasks in last run
ara result list --playbook-id <id> --changed
# GitLab: trigger drift-detection pipeline manually
glab pipeline run --ref main --variables CI_PIPELINE_SOURCE=scheduleTODO: Set alert target (email/Slack/PagerDuty webhook) once notification config is available from ingested runbooks. TODO: Define drift-remediation SLA (time-to-remediate thresholds) once the change- management policy doc is ingested. TODO: Add ARA Postgres connection string from environment discovery.
Deep Reference
Scheduled Drift Check Pipeline
# .gitlab-ci.yml — drift detection (scheduled only)
drift-check:
stage: drift
tags: [linux, deploy, ansible]
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
script:
- ansible-playbook --check --diff site.yml -i inventory/prod/ 2>&1 | tee drift-report.txt
- if grep -q "changed:" drift-report.txt; then echo "DRIFT DETECTED"; exit 1; fi
artifacts:
paths: [drift-report.txt]
expire_in: 30 days
allow_failure: false # drift is an alert conditionARA Record Tagging
Tag every run with commit SHA and pipeline ID for traceability:
ansible-playbook --check --diff site.yml \
-e ara_playbook_labels='{"commit":"$CI_COMMIT_SHA","pipeline":"$CI_PIPELINE_ID"}'Drift Alert Routing
When drift is detected:
- CI job fails with non-zero exit
- GitLab sends a pipeline failure notification
- On-call rotation is responsible for investigating
- The infra-auditor agent can be invoked to produce a detailed drift report
- Remediation goes through the standard iac-author → review gate → merge flow
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

