molecule icon indicating copy to clipboard operation
molecule copied to clipboard

The dependency options are not universal when galaxy is using collections vs roles

Open minsis opened this issue 9 months ago • 3 comments

Prerequisites

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

Environment

molecule 25.4.0 using python 3.13 ansible:2.18.3 gce:23.7.0 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0 default:25.4.0 from molecule containers:23.7.0 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1 vagrant:23.7.0 from molecule_plugins openstack:23.7.0 from molecule_plugins requiring collections: openstack.cloud>=2.1.0 podman:23.7.0 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0 azure:23.7.0 from molecule_plugins ec2:23.7.0 from molecule_plugins docker:23.7.0 from molecule_plugins requiring collections: community.docker>=3.10.2 ansible.posix>=1.4.0

What happened

If you have to specifiy ansible-galaxy options in the dependency stage, the options are passed to both collection and role commands. For example, If I set --collections-path option and provide both requirements.yml and collections.yml files, then the dependency stage applies --collections-path to ansible-galaxy role install, in which this option does not exist for role installs.

Reproducing example

dependency:
  name: "galaxy"
  options:
    force: true
    collections-path: ../.ansible/collections
    requirements-file: ./collections.yml

driver:
  name: "docker"

provisioner:
  name: "ansible"
  playbooks:
    prepare: ../default/prepare.yml
    converge: ../default/converge.yml
    verify: ../default/verify.yml
  connection_options:
    ansible_become: true
  env:
    ANSIBLE_COLLECTIONS_PATH: ../../../.ansible/collections

verifier:
  name: "ansible"

platforms:
  - name: "molecule-rhel8"
    image: registry.redhat.io/ubi8/ubi:latest
    privileged: true

minsis avatar Apr 11 '25 17:04 minsis

Hi @minsis, can you provide more information about what outcome you're expecting from the command? Or if there is an error or unexpected output present?

alisonlhart avatar May 28 '25 12:05 alisonlhart

I've hit similar issues with this, our requirements.yml contains both roles & collections.

Setting the config as:

dependency:
  options:
    requirements-file: ${MOLECULE_PROJECT_DIRECTORY}/../../requirements.yml
    upgrade: yes

only installs collections. You need to also specify role_file like so:

dependency:
  options:
    role-file: ${MOLECULE_PROJECT_DIRECTORY}/../../requirements.yml
    requirements-file: ${MOLECULE_PROJECT_DIRECTORY}/../../requirements.yml
    upgrade: yes

While results in --upgrade being passed to the role command and causing it to fail:

[root@molecule-wrapper]/workdir/ansible/roles/keycloak# molecule -vvv create                                 
INFO     Found config file /root/.config/molecule/config.yml
DEBUG    Validating schema /workdir/ansible/roles/keycloak/molecule/default/molecule.yml.
WARNING  Driver docker does not provide a schema.
INFO     default scenario test matrix: dependency, create, prepare
INFO     Performing prerun with role_name_check=2...
INFO     Running default > dependency
usage: ansible-galaxy [-h] [--version] [-v] TYPE ...
ansible-galaxy: error: unrecognized arguments: --upgrade

usage: ansible-galaxy [-h] [--version] [-v] TYPE ...

Perform various Role and Collection related operations.

positional arguments:
  TYPE
    collection   Manage an Ansible Galaxy collection.
    role         Manage an Ansible Galaxy role.

options:
  --version      show program's version number, config file location,
                 configured module search path, module location, executable
                 location and exit
  -h, --help     show this help message and exit
  -v, --verbose  Causes Ansible to print more debug messages. Adding multiple
                 -v will increase the verbosity, the builtin plugins currently
                 evaluate up to -vvvvvv. A reasonable level to start is -vvv,
                 connection debugging might require -vvvv. This argument may
                 be specified multiple times.

liamjones avatar Jun 27 '25 12:06 liamjones

RFE for this would be to create role-options and collection-options params under options so the framework can individually pass specific options to either.

isuftin avatar Sep 04 '25 20:09 isuftin