Using Ansible Collections in molecule test

31 views
Skip to first unread message

ksam...@redhat.com

unread,
Jul 10, 2020, 11:20:47 PM7/10/20
to Ansible Project
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 ?  

Abhijeet Kasurde

unread,
Jul 10, 2020, 11:35:15 PM7/10/20
to ansible...@googlegroups.com
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.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1f2320e3-e0ff-41eb-ad27-234e467adeadn%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

kameshs

unread,
Jul 11, 2020, 2:16:24 AM7/11/20
to Ansible Project
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
    /
....
```

kameshs

unread,
Jul 11, 2020, 2:37:52 AM7/11/20
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages