Skip to content

Fix "ansible_" variable deprecations - use "ansible_facts" - #325

Merged
bubacoder merged 1 commit into
mainfrom
feature/ansible-roles
May 4, 2026
Merged

Fix "ansible_" variable deprecations - use "ansible_facts"#325
bubacoder merged 1 commit into
mainfrom
feature/ansible-roles

Conversation

@bubacoder

@bubacoder bubacoder commented May 3, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Chores
    • Updated internal deployment configuration to standardize variable references across multiple configuration files for improved consistency and maintainability.

@coderabbitai

coderabbitai Bot commented May 3, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Multiple Ansible task files are updated to use the ansible_facts dictionary access pattern instead of deprecated top-level variables (ansible_distribution, ansible_distribution_release, ansible_system). The changes maintain existing logic while aligning with modern Ansible fact access standards.

Changes

Ansible Facts Migration

Layer / File(s) Summary
Distribution Facts
ansible/roles/debian_base/tasks/50-crowdsec.yaml, ansible/roles/debian_docker_host/tasks/10-docker-Debian.yaml, ansible/roles/debian_docker_host/tasks/10-docker-Ubuntu.yaml
Repository URL templates are updated to reference ansible_facts["distribution"] and ansible_facts["distribution_release"] instead of the deprecated ansible_distribution and ansible_distribution_release variables.
Task Wiring
ansible/roles/debian_docker_host/tasks/main.yaml
Docker install task file selection via with_first_found now uses ansible_facts['distribution'] instead of ansible_distribution to determine which OS-specific task file to include.
System Platform Checks
ansible/roles/debian_tools/tasks/20-homebrew.yaml, ansible/roles/mac_base/tasks/10-homebrew.yaml
Conditional checks for Homebrew installation are updated to use ansible_facts["system"] instead of ansible_system, with individual task-level when conditions replacing prior consolidated conditionals.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the pull request: replacing deprecated Ansible variables with the modern ansible_facts approach across multiple task files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/ansible-roles

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ansible/roles/mac_base/tasks/10-homebrew.yaml (1)

3-25: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Register variable clobbered on Linux — runtime failure for mac_base_homebrew_check.stat.exists

Ansible always registers something in a registered variable for every host, even on hosts where a task fails or Ansible skips a task because a condition is not met. This means a skipped task still overwrites the register variable with {skipped: true, changed: false, …} — without any .stat sub-key.

On a Linux host the execution order is:

  1. Task at line 3-7 runs (system == "Linux" → true) → mac_base_homebrew_check receives the full stat result including .stat.exists.
  2. Task at line 9-13 is skipped (system == "Darwin" → false) → mac_base_homebrew_check is overwritten with the skipped sentinel — .stat is gone.

Downstream tasks at lines 18 and 25 then dereference mac_base_homebrew_check.stat.exists, which fails with an undefined-attribute error. This is because the variable gets overwritten by the second task, even if it is skipped.

The Darwin path happens to work only because the Darwin stat task is last, so it wins the overwrite race on macOS.

🐛 Proposed fix — use distinct register names and a resolving set_fact
 - name: Check if Homebrew is installed
   ansible.builtin.stat:
     path: /home/linuxbrew/.linuxbrew/bin/brew
-  register: mac_base_homebrew_check
+  register: mac_base_homebrew_check_linux
   when: ansible_facts["system"] == "Linux"

 - name: Check if Homebrew is installed
   ansible.builtin.stat:
     path: /opt/homebrew/bin/brew
-  register: mac_base_homebrew_check
+  register: mac_base_homebrew_check_darwin
   when: ansible_facts["system"] == "Darwin"

+- name: Resolve Homebrew check result for this platform
+  ansible.builtin.set_fact:
+    mac_base_homebrew_check: >-
+      {{ mac_base_homebrew_check_linux if ansible_facts["system"] == "Linux"
+         else mac_base_homebrew_check_darwin }}

 - name: Install Homebrew
   ansible.builtin.shell: /bin/bash -c "NONINTERACTIVE=true $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ansible/roles/mac_base/tasks/10-homebrew.yaml` around lines 3 - 25, The
register mac_base_homebrew_check is being clobbered by two conditional stat
tasks; change the first stat register to mac_base_homebrew_check_linux and the
second to mac_base_homebrew_check_darwin, then add a resolving set_fact (e.g.,
set_fact: mac_base_homebrew_exists="{{
(mac_base_homebrew_check_linux.stat.exists | default(false)) or
(mac_base_homebrew_check_darwin.stat.exists | default(false)) }}") and update
downstream when conditions to use mac_base_homebrew_exists (and reference
mac_base_homebrew_install for changed_when) so the install/update tasks no
longer dereference a skipped register.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@ansible/roles/mac_base/tasks/10-homebrew.yaml`:
- Around line 3-25: The register mac_base_homebrew_check is being clobbered by
two conditional stat tasks; change the first stat register to
mac_base_homebrew_check_linux and the second to mac_base_homebrew_check_darwin,
then add a resolving set_fact (e.g., set_fact: mac_base_homebrew_exists="{{
(mac_base_homebrew_check_linux.stat.exists | default(false)) or
(mac_base_homebrew_check_darwin.stat.exists | default(false)) }}") and update
downstream when conditions to use mac_base_homebrew_exists (and reference
mac_base_homebrew_install for changed_when) so the install/update tasks no
longer dereference a skipped register.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 04c8cfbb-e22a-4a83-8ebd-22f44798cf4c

📥 Commits

Reviewing files that changed from the base of the PR and between 9e57584 and a996408.

📒 Files selected for processing (6)
  • ansible/roles/debian_base/tasks/50-crowdsec.yaml
  • ansible/roles/debian_docker_host/tasks/10-docker-Debian.yaml
  • ansible/roles/debian_docker_host/tasks/10-docker-Ubuntu.yaml
  • ansible/roles/debian_docker_host/tasks/main.yaml
  • ansible/roles/debian_tools/tasks/20-homebrew.yaml
  • ansible/roles/mac_base/tasks/10-homebrew.yaml

@bubacoder
bubacoder merged commit c1914ec into main May 4, 2026
6 checks passed
@bubacoder
bubacoder deleted the feature/ansible-roles branch May 4, 2026 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant