openshift-applier icon indicating copy to clipboard operation
openshift-applier copied to clipboard

Unable to test via molecule own role with a dependency to openshift-applier

Open matihost opened this issue 5 years ago • 0 comments

If own role uses molecule and uses openshift-applier dependency to - the "openshift-applier" role is run with empty results.

The reason is the openshift-applier git repository equals to the name of the role "openshift-applier" So even adding :

provisioner:
  name: ansible
  log: True
  env:
    ANSIBLE_ROLES_PATH: /tmp/molecule/role-under-test/default/roles/openshift-applier/roles

does not help because molecule append ANSIBLE_ROLES_PATH to ansible rolepath at the end. Since /tmp/molecule/role-under-test/default/roles is earlier on the role path, Ansiblefinds /tmp/molecule/role-under-test/default/roles/ansible-applier directory - which is not valid Ansible role - and it assumes role is empty.

So when Ansible looks for "openshift-applier" role, it finds it earielir (and find the git repository name) and assumes empty.

The problem could be solved in various ways:

  • openshift-applier repo to follow Ansible role directory structure from the top git repo level
  • moving to gilt in molecule but an attempt to download only src: roles/openshift-applier ends with "[Errno 40] Too many levels of symbolic links: '/home/user/.gilt/clone/.openshift-applier/roles/openshift-applier/tests/roles/openshift-applier/tests/roles/openshift-applier/tests/roles/openshift-applier/tests/roles/openshift-appbblablabla'")] - it seems gilt doesn't like symbolic links.
  • ansible galaxy to allow importing subdirectories of git repos
  • molecule - to change mind with https://github.com/ansible/molecule/issues/1273 - to allow overriding role path or to allows to inject own directories to role path before core rolepath list

Workaround is:

  • disable molecule dependency step
  • run galaxy or gogitit or git submodules to download openshitt-applier
  • add 'openshift-applier/roles/' to molecule ANSIBLE_ROLES_PATH env

Sample makefile to automate stuff:

test: clean get-dependencies ## Test own role
	molecule test

get-dependencies: clean ## download galaxy dependencies
	ansible-galaxy install -r requirements.yml -p galaxy -f

clean:
	-rm -rf galaxy

where molecule.yml is the following:

# cannot use with Ansible role where git role is in subdirectory, and role name equals git repo (for example https://github.com/redhat-cop/openshift-applier.git)
#dependency:
#  name: galaxy
#  options:
#    role-file: requirements.yml
#dependency:
#  name: shell
#  command: gilt overlay
#  options:
#    debug: True
driver:
  name: docker
lint:
  name: yamllint
  options:
    config-file: .yamllint
platforms:
  - name: instance
    image: centos:7
provisioner:
  name: ansible
  log: True
  env:
    ANSIBLE_ROLES_PATH: ../../galaxy/openshift-applier/roles
  lint:
    name: ansible-lint
    options:
      force-color: True
      c: .ansible-lint
  options:
    v: true
scenario:
  name: default
  test_sequence:
    - lint
    - destroy
    #- dependency
    - syntax
    - create
    - prepare
    - converge
    - idempotence
    - side_effect
    - verify
    - destroy

verifier:
  name: testinfra
  lint:
    name: flake8

matihost avatar Mar 13 '19 10:03 matihost