ansible / molecule

Molecule aids in the development and testing of Ansible content: collections, playbooks and roles
https://ansible.readthedocs.io/projects/molecule/
MIT License
3.89k stars 664 forks source link

Error when attempting to test collection playbooks using FQCN #4244

Open FragmentedPacket opened 5 months ago

FragmentedPacket commented 5 months ago

Prerequisites

Environment

molecule 24.6.1.dev39 using python 3.10 ansible:2.17.1 default:24.6.1.dev39 from molecule

What happened

I have the following converge.yml that is being called to test a playbook that exists in a collection.

---
- ansible.builtin.import_playbook: yo.test.test_playbook

I get the following error when running molecule test --all

❯ molecule test --all
INFO     Performing prerun with role_name_check=0...
INFO     Running test_playbook > converge
ERROR! Unable to retrieve file contents
Could not find or access '/Users/myohman/local-dev/molecule-test/yo/molecule/test_playbook/yo.test.test_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 /Users/myohman/.cache/molecule/yo/test_playbook/inventory --skip-tags molecule-notest,notest /Users/myohman/local-dev/molecule-test/yo/molecule/test_playbook/converge.yml
WARNING  An error occurred during the test sequence action: 'converge'. Cleaning up.
INFO     Running test_playbook > cleanup
WARNING  Skipping, cleanup playbook not configured.
INFO     Running test_playbook > 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

My expectation is it would load a playbook from a collection.

Reproducing example

(I tested with multiple versions of Ansible Core and Molecule, you should be able to use the latest of both and reproduce)

  1. ansible-galaxy collection init yo.test
  2. cd yo
  3. molecule init scenario test_playbook
  4. mkdir playbooks && touch test_playbook.yml
  5. Add the follow play to test_playbook.yml
    ---
    - hosts: localhost
    tasks:
    - name: Test task
      debug:
        msg: "Hello, world!"
  6. Update molecule/test_playbook/converge.yml
    ---
    - ansible.builtin.import_playbook: yo.test.test_playbook
  7. Add scenario and only the converge test molecule/test_playbook/molecule.yml
    ---
    scenario:
    test_sequence:
    - converge
    driver:
    name: default
    platforms:
    - name: instance
  8. Run molecule init scenario test_playbook