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.9k stars 666 forks source link

molecule schema validation doesnt recognize credentials field for docker registry #3710

Closed avictor0826 closed 2 years ago

avictor0826 commented 2 years ago

Issue Type

Molecule and Ansible details

[root@b986aafc8d59 ~]# ansible --version && molecule --version
ansible [core 2.13.5]
  config file = /home/gitlab-runner/ansible.cfg
  configured module search path = ['/home/gitlab-runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/gitlab-runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.2 (default, Mar  3 2021, 09:23:36) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
  jinja version = 3.1.2
  libyaml = True
molecule 4.0.3 using python 3.9
    ansible:2.13.5
    delegated:4.0.3 from molecule
    docker:2.1.0 from molecule_docker requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0

Molecule installation method (one of):

Ansible installation method (one of):

Detail any linters or test runners used:

Desired Behavior

A snippet of molecule.yml we use

dependency:
  name: galaxy
driver:
  name: docker
lint: |
        yamllint . && ansible-lint .
platforms:
  - name: httpd_test_instance
    image: middleware/centos-scl-httpd
    registry:
      url: docker.company.com
      credentials:
        username: foo
        password: baar
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    privileged: true
    command: "/usr/sbin/init"
provisioner:
  name: ansible
....

Molecule.yml schema validation should recognize the credentials field and a molecule lint should not error out

Actual Behaviour

When i run molecule lint i get the below failure message

[root@b986aafc8d59 java]# molecule --debug lint
DEBUG    Validating schema /home/user1/roles/httpd/molecule/default/molecule.yml.
CRITICAL Failed to validate /home/user1/roles/httpd/molecule/default/molecule.yml

["Additional properties are not allowed ('credentials' was unexpected)"]

The issue is because the molecule.json here doesnt recognize credentials as a field nor does it allow additionalProperties

the registry.credentials is an allowed, if not expected, field in the cookiecutter create.yml in the molecule-docker as given here

Since we use a docker registry which doesnt have anonymous access, it is necessary for us to furnish the credentials. Even if this could be done by having a seperate create.yml it would mean a lot of work refactoring the roles and also we want to stick with the cookiecutter playbooks for molecule testings to keep ourselves up to date with the newest features.

Proposed fix

Add the credentials into the molecule schema so that it is recognized in the molecule.json Or we could set the "additionalProperties": true, to allow these fields

Please let me know if there is any other details required or any help required in fixing this.

mnaser commented 2 years ago

@avictor0826 is this fixed by https://github.com/ansible-community/molecule/commit/c04706c66a9f345473be31e40fde2085c8918452 ? :)

avictor0826 commented 2 years ago

@mnaser that is exactly what i was hoping for.. thanks @TheLastProject for the fix.. closing the issue.