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.88k stars 662 forks source link

molecule.yml: platforms[].env cannot be a dictionary #3684

Closed ollie1 closed 2 years ago

ollie1 commented 2 years ago

Issue Type

Molecule and Ansible details

$ ansible --version && molecule --version
ansible [core 2.13.2]
  config file = None
  configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.13 (default, Jun 24 2022, 15:27:57) [GCC 8.5.0 20210514 (Red Hat 8.5.0-13)]
  jinja version = 3.1.2
  libyaml = True
molecule 4.0.2 using python 3.8 
    ansible:2.13.2
    delegated:4.0.2 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

Molecule 4.0.2 should work with the same molecule.yml as 4.0.1

Actual Behaviour

To reproduce, generate a standard molecule role as follows:

molecule init role acme.myrole -d docker

Modify molecule.yml to add env as follows

---
dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: instance
    image: quay.io/centos/centos:stream8
    pre_build_image: true
    env:
      http_proxy: http://127.0.0.1:8080
provisioner:
  name: ansible
verifier:
  name: ansible

Run molecule create, and observe that an error is shown.

$ molecule create
CRITICAL Failed to validate /runner/home/username/myrole/molecule/default/molecule.yml

["{'http_proxy': 'http://127.0.0.1:8080'} is not of type 'array'"]

In molecule 4.0.1, this works as expected. In 4.0.2 this behaviour has broken, and we must change the env keys in our molecule.yml to an array. If this is intentional, it's a breaking change and it should be mentioned it in the release note - hopefully it's just a bug caused by the json schema changes.

zhan9san commented 2 years ago

@ollie1

You are right. It's just a schema issue.

It should be a dict, and could you help submit a PR to fix it?

https://github.com/ansible-community/molecule/blob/764258fa544bf80b6a8236c50b2f4b0f25f25c9f/src/molecule/data/molecule.json#L165-L171

I can help review it.

Reference:

zeitounator commented 2 years ago

@zhan9san See the linked PR. Tested on a personal role which was failing that validation.

Edit: had to fix the tox -e lint corresponding test too.

The current definition at least used with several vars, e.g.

env:
  - Hello: World!
  - Wa: Zaaaa!

fails the create sequence with the docker driver anyway with the following error

"argument 'env' is of type <class 'list'> and we were unable to convert to dict: <class 'list'> cannot be converted to a dict"

For the records: I tested (as allowed by many ansible environment related settings)

env:
  - toto=1
  - pipo=2

which was not supported by docker driver either with the same error as above