Fix "ansible_" variable deprecations - use "ansible_facts" - #325
Conversation
WalkthroughMultiple Ansible task files are updated to use the ChangesAnsible Facts Migration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
There was a problem hiding this comment.
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 winRegister variable clobbered on Linux — runtime failure for
mac_base_homebrew_check.stat.existsAnsible 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.statsub-key.On a Linux host the execution order is:
- Task at line 3-7 runs (
system == "Linux"→ true) →mac_base_homebrew_checkreceives the fullstatresult including.stat.exists.- Task at line 9-13 is skipped (
system == "Darwin"→ false) →mac_base_homebrew_checkis overwritten with the skipped sentinel —.statis 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
stattask 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
📒 Files selected for processing (6)
ansible/roles/debian_base/tasks/50-crowdsec.yamlansible/roles/debian_docker_host/tasks/10-docker-Debian.yamlansible/roles/debian_docker_host/tasks/10-docker-Ubuntu.yamlansible/roles/debian_docker_host/tasks/main.yamlansible/roles/debian_tools/tasks/20-homebrew.yamlansible/roles/mac_base/tasks/10-homebrew.yaml
Summary by CodeRabbit