Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ollie1 opened this issue Oct 17, 2022 · 2 comments · Fixed by #3690
Closed

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

ollie1 opened this issue Oct 17, 2022 · 2 comments · Fixed by #3690
Labels

Comments

@ollie1
Copy link

ollie1 commented Oct 17, 2022

Issue Type

  • Bug report

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):

  • pip

Ansible installation method (one of):

  • pip

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.

@ollie1 ollie1 added the bug label Oct 17, 2022
@zhan9san
Copy link
Contributor

@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
Copy link
Contributor

zeitounator commented Oct 20, 2022

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants