Using Ansible Collections in molecule test

I am trying to use Ansible collections with my molecule test

molecule.yml


---
dependency:
name: galaxy
options:
requirements-file: molecule/common/requirements.yml
driver:
name: delegated
options:
managed: False
ansible_connection_options:
ansible_connection: local
lint: |
set -e
yamllint .
platforms:
- name: molecule-kind-ingress
provisioner:
name: ansible
verifier:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}

With my converge.yml


---
- name: Converge
hosts: localhost
connection: local

collections:
- community.kubernetes

vars:
ansible_python_interpreter: '{{ ansible_playbook_python }}'
cluster_name: molecule-ingress
kind_home_dir: "/tmp/kind_test"
deploy_ingress: True

roles:
- role: kameshsampath.kind

When running the test molecule is not picking up my collection, eventually resulting in a playbook error like:


fatal: [localhost]: FAILED! => {
"reason": "couldn't resolve module/action 'helm_repository'. This often indicates a misspelling, missing collection, or incorrect module path.\n\nThe error appears to be in '/Users/kameshs/git/kameshsampath/kameshsampath.kind/tasks/ingress.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Add stable chart Repo\n ^ here\n"
}

my requirements.yml does have the following entry


---
collections:
- community.kubernetes

I am not sure if I am missing anything here ?

Hi,

Could you please provide ansible-galaxy collection list output? helm_repository is added in Kubernetes collection 0.11.0. If your version Kubernetes collection is less than this then you need to update.

I don’t see a ansible-galaxy collection list command but this is what I see with debug at start of molecule test

ANSIBLE_COLLECTIONS_PATHS=/Users/kameshs/.cache/molecule/kameshsampath.kind/deploy_ingress/collections: ...

and during dependency step of the scenario I see the output like

...

Reading requirement file at '/Users/kameshs/git/kameshsampath/kameshsampath.kind/molecule/common/requirements.yml'
Process install dependency map
Opened /Users/kameshs/.ansible/galaxy_token
Processing requirement collection 'community.kubernetes'
Collection 'community.kubernetes' obtained from server default https://galaxy.ansible.com/api/
Starting collection install process
Installing 'community.kubernetes:0.11.1' to '/Users/kameshs/.cache/molecule/kameshsampath.kind/deploy_ingress/collections/ansible_collections/community/kubernetes'
Downloading https://galaxy.ansible.com/download/community-kubernetes-0.11.1.tar.gz to /Users/kameshs/.ansible/tmp/ansible-local-7917k7r02p09/tmph3nh7p5h
/

....

I tried using the fully qualified name like community.kubernetes.helm_repository, then it does pick it up. I don’t understand why that way inspite of me adding collections: ["community.kubernetes"] as part of the playbook