ansible/molecule

Getting Started example: Molecule looking for namespace.collection.role within the molecule directory structure

daurrutia opened this issue · 10 comments

Prerequisites

  • This was not already reported in the past (duplicate check)
  • It does reproduce it with code from main branch (latest unreleased version)
  • I include a minimal example for reproducing the bug
  • The bug is not trivial, as for those a direct pull-request is preferred
  • Running pip check does not report any conflicts
  • I was able to reproduce the issue on a different machine
  • The issue is not specific to any driver other than 'default' one

Environment

molecule 6.0.0 using python 3.9
ansible:2.15.3
default:6.0.0 from molecule

macos

What happened

% molecule test
INFO     default scenario test matrix: dependency, cleanup, destroy, syntax, create, prepare, converge, idempotence, side_effect, verify, cleanup, destroy
INFO     Performing prerun with role_name_check=0...
INFO     Running default > dependency
WARNING  Skipping, missing the requirements file.
WARNING  Skipping, missing the requirements file.
INFO     Running default > cleanup
WARNING  Skipping, cleanup playbook not configured.
INFO     Running default > destroy

PLAY [Destroy] *****************************************************************

TASK [Populate instance config] ************************************************
ok: [localhost]

TASK [Dump instance config] ****************************************************
skipping: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

INFO     Running default > syntax
ERROR! Unable to retrieve file contents
Could not find or access '/Users/username/.ansible/collections/ansible_collections/daurrutia/devtooling_collx/extensions/molecule/default/daurrutia.devtooling_collx.setup_playbook.yml' on the Ansible Controller.
If you are using a module and expect the file to exist on the remote, see the remote_src option
CRITICAL Ansible return code was 1, command was: ansible-playbook --inventory /Users/username/.cache/molecule/extensions/default/inventory --skip-tags molecule-notest,notest --syntax-check /Users/username/.ansible/collections/ansible_collections/daurrutia/devtooling_collx/extensions/molecule/default/converge.yml
WARNING  An error occurred during the test sequence action: 'syntax'. Cleaning up.
INFO     Running default > cleanup
WARNING  Skipping, cleanup playbook not configured.
INFO     Running default > destroy

PLAY [Destroy] *****************************************************************

TASK [Populate instance config] ************************************************
ok: [localhost]

TASK [Dump instance config] ****************************************************
skipping: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

INFO     Pruning extra files from scenario ephemeral directory

Following the getting started guide to test a simple playbook targeting localhost.

I created the collection within ~/.ansible/collections

Following the getting started guide, changed the names to my namespace and desired role name.

The collection is not published at all, simply local to my machine.

Q: Is there a way to have molecule look to the above collection dir structure instead of within the molecule dir?

Tagging some folks that have contributed to the community @ajinkyau @ssbarnea @geerlingguy - Thanks!

Reproducing example

No response

This is my dir structure:

daurrutia % tree 
.
└── devtooling_collx
    ├── README.md
    ├── docs
    ├── extensions
    │   ├── ansible.cfg
    │   └── molecule
    │       └── default
    │           ├── converge.yml
    │           ├── create.yml
    │           ├── destroy.yml
    │           └── molecule.yml
    ├── galaxy.yml
    ├── meta
    │   └── runtime.yml
    ├── playbooks
    │   └── setup-playbook.yml
    ├── plugins
    │   └── README.md
    └── roles
        └── setup_role
            ├── README.md
            ├── defaults
            │   └── main.yml
            ├── files
            ├── handlers
            │   └── main.yml
            ├── meta
            │   └── main.yml
            ├── tasks
            │   └── main.yml
            ├── templates
            ├── tests
            │   ├── inventory
            │   └── test.yml
            └── vars
                └── main.yml

19 directories, 18 files

Resolved.

Issue was due to a file naming convention issue on my end.

I am currently having the exact same issue trying to get thru the getting-started guide. my converge.yml looks like this:

---
- name: Converge
  hosts: all
  gather_facts: false
  tasks:
    - name: Replace this task with one that validates your content
      ansible.builtin.debug:
        msg: "This is the effective test"

- name: Include a playbook from a collection
  ansible.builtin.import_playbook: bignose.collection1.my_playbook

And my tree looks like this:

❯ tree
.
└── bignose
    └── collection1
        ├── docs
        ├── extensions
        │   └── molecule
        │       └── default
        │           ├── converge.yml
        │           ├── create.yml
        │           ├── destroy.yml
        │           └── molecule.yml
        ├── galaxy.yml
        ├── meta
        │   └── runtime.yml
        ├── playbooks
        │   └── my_playbook.yml
        ├── plugins
        │   └── README.md
        ├── README.md
        └── roles
            └── learn-molecule
                ├── defaults
                │   └── main.yml
                ├── files
                ├── handlers
                │   └── main.yml
                ├── meta
                │   └── main.yml
                ├── README.md
                ├── tasks
                │   └── main.yml
                ├── templates
                ├── tests
                │   ├── inventory
                │   └── test.yml
                └── vars
                    └── main.yml

I'm curious which naming convention tripped you up?

Your converge.yml looks right.

I had to ensure that my collection (directory) name matched the value of name: in galaxy.yml and within the import lines in converge.yml and the playbook.yml.

This is the first few lines of my galaxy.yml (which are unchanged. They were created by ansible-galaxy when I made the collection)

namespace: bignose
name: collection1
version: 1.0.0
readme: README.md

Here's the output of running it:

INFO     Running default > converge
ERROR! Unable to retrieve file contents
Could not find or access '/home/jmacdonald/code/molecule-learning/bignose/collection1/extensions/molecule/default/bignose.collection1.my_playbook' on the Ansible Controller.
If you are using a module and expect the file to exist on the remote, see the remote_src option
CRITICAL Ansible return code was 1, command was: ansible-playbook --inventory /home/jmacdonald/.cache/molecule/extensions/default/inventory --skip-tags molecule-notest,notest /home/jmacdonald/code/molecule-learning/bignose/collection1/extensions/molecule/default/converge.yml