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"