From af0e334404f5ed824c396f5751714be2edb4ffbf Mon Sep 17 00:00:00 2001 From: Matthew Mellor Date: Mon, 16 Mar 2026 12:44:45 -0500 Subject: [PATCH] fix(ansible): check collection list output instead of exit code ansible-galaxy collection list exits 0 even when the collection is not installed, so the idempotency check was always true and the install was skipped. Check grep output for the collection name instead. Co-Authored-By: Claude Opus 4.6 --- scripts/install-ansible.sh | 4 +++- tests/test-ansible.sh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/install-ansible.sh b/scripts/install-ansible.sh index 68fb732..06e0459 100644 --- a/scripts/install-ansible.sh +++ b/scripts/install-ansible.sh @@ -72,7 +72,9 @@ fi # Install community.general collection (idempotent) # Required for yaml callback plugin, json_query filter, and many common modules -if ansible-galaxy collection list community.general &>/dev/null; then +# Note: ansible-galaxy collection list exits 0 even when not installed, +# so we check the output for the collection name instead of the exit code. +if ansible-galaxy collection list community.general 2>/dev/null | grep -q community.general; then log_info "community.general collection is already installed, skipping" else log_info "Installing community.general Ansible collection" diff --git a/tests/test-ansible.sh b/tests/test-ansible.sh index 5b08714..c2342c9 100644 --- a/tests/test-ansible.sh +++ b/tests/test-ansible.sh @@ -51,7 +51,9 @@ check_tool "ansible-lint" "--version" check_tool "molecule" "--version" # Verify community.general collection is installed -if ansible-galaxy collection list community.general &>/dev/null; then +# Note: ansible-galaxy collection list exits 0 even when not installed, +# so we check the output for the collection name instead of the exit code. +if ansible-galaxy collection list community.general 2>/dev/null | grep -q community.general; then log_info "community.general collection — OK" else log_error "community.general Ansible collection is not installed"