Molecule and Ansible version compatibility

There are users in my organisation who expect a production playbook (executed in Ansible Tower) to run with Ansible version 2.9. The playbook itself is a bit of a hot mess and I’m looking to clean it up. As part of the clean up process I’d like to bring in Molecule testing of the code and then start to refactor it and make it ready for more recent Ansible version.

Is there a way to make Molecule work with such an old version of Ansible?

Can Molecule, even an older version work with such an old version of Ansible? If not, is there a way to run it with a compatible version of Ansible in such a way as to be as close as possible to the behaviour of 2.9?

Hi,

Is there a way to make Molecule work with such an old version of Ansible?

Possibly an older version of Molecule, yes. Problem is, there isn’t to my knowledge a compatibility matrix to match Ansible versions to Molecule’s, although there was an issue opened at some point on this matter.

You could try to use pipdeptree package or something similar to get info on molecule package: pipdeptree -p molecule -j, with a bit of jq magic to parse the output, getting info specifically on ansible-core package.

To try on different versions on molecule from the same era as ansible-core 2.9, which you could look for in molecule project releases, to try to find one that supports ansible-core <=2.9.

I’d suggest you use python virtualenvs / venvs or containers, so you don’t break your Ansible install, as ansible-core is a dependency for molecule, which means pip (and surely other Python packages managers) will try to upgrade it if you try to use a more recent version. Also lets you rebuild as needed.

That being said, I’d probably do it the other way around, upgrading Ansible binaries in on go (in a venv), then using current molecule version to work on my playbooks. After that, you could try to run your (tested) playbooks again in 2.9, if you really need to keep supporting this environment.

One last thing; it seems to me you are looking for a way to cleanup code, and as much useful molecule is, it’s more of a tool you’d use to test specific scenarios, or simply ensuring your role is working fine on specified platforms. ansible-lint might be a better fit for your usecase IMO.

Disclaimer: I’m not very familiar with Python ecosystem, so take my suggestions with a grain of salt.

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.