ansiblegitlabmolecule

Molecule dependency in private gitlab


Is there any way how i can resolve dependencies from private project in gitlab? On my actual gitlab-ci i use such a trick

requirements.tmpl:

- name: my-company.ansible-init-disk
  scm: git
  src: https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.my-company/sre/ansible-roles/ansible-role-init-disk.git
  version: 0.1.0

.gitlab-ci.yaml

- envsubst < requirements.tmpl > requirements.yaml
- ansible-galaxy install -r requirements.yaml -p roles --force-with-deps

And voila i got my deps in roles folder.

For molecule i have to do something like

dependency:
  name: galaxy
  options:
    role-file: molecule/default/requirements.yml

but of cause there is no env interpolation in requirements.yml. see https://github.com/ansible/ansible/issues/36395

Any ideas how to get my deps ?


Solution

  • Current best solution looks like that

    molecule.yml

    dependency:
      name: shell
      command: $PWD/molecule/default/deps.sh
    

    deps.sh

    envsubst < molecule/default/requirements.tmpl > molecule/default/requirements.yaml
    ansible-galaxy install -r molecule/default/requirements.yaml
    

    but that look bit ugly