Using Exec Environment for Molecule images?

So forgive me if this question’s a bit elementary… I’m just wading into the Molecule pool but, if I’m using AAP and would be wanting to use Molecule to help in my dev testing process. Is it possible to somehow incorporate EE’s into Molecule?

If not is that normally just something you make sure are identical… the EE and your testing environment in a manual sort of way?


Maybe @ssbarnea has some advice here?

I’m assuming you could really use any valid container… but if a person is wanting to use Molecule to help test content that’s destined to be initiated from AAP then it’d be super to be able to test using the EE that prod would be using.

1 Like

So I was/am looking for a way to test playbooks (not Roles) while at the same time using the Execution Environments other than manually loading the image, kicking off a bash prompt inside, a lot of copy/pasting, etc, etc.
Surely people out there have an automated testing process utilizing EE’s, right? I’m the only idiot doing it manually… right?
This is not sarcasm either… I’ve googled my entire ass off and have not stumbled across anything yet.

I don’t have an exact answer to your question (How to test using molecule and EE). I’m actually wondering about the same thing.

However, here are a few pointers on the subject that might help:

  1. To mimic our Ansible development environment as closely as possible the (EE), we simply currently import a subset of the EE python requirements.txt into a virtual environment (venv).

  2. You can test playbooks using Molecule. Although it’s not its original purpose, we’ve been using it successfully for a while now. The simplest way might be to use an import task in converge.yml. For a more comprehensive solution, I’ve posted an example below of what we to test our main provisioning playbook with an instance of the “dev_infra” group, using variables from the production inventory.

hope this helps…

# Provision test: infra_projet_xyz/tests/playbook-tests/provision/
# Provision playbook to test: infra_projet_xyz/prod_playbooks/provision.yml
# Global molecule configuration is located in .config/molecule
lint: |
  set -e
  export ANSIBLE_ROLES_PATH=../../../roles
  yamllint ../../../playbooks/provision.yml
  ansible-lint ../../../playbooks/provision.yml

# platforms: use default
  name: ansible
    ANSIBLE_CONFIG: ../../../../../ansible.cfg
    ANSIBLE_ROLES_PATH: ../../../../../roles
    converge: ../../../../../prod_playbooks/provision.yml
    links: # Testing inventory, using production vars
      hosts: ../../inventory/hosts_default
      host_vars: ../../inventory/host_vars/
      group_vars: ../../../../../prod_inventory/group_vars/
            hosts: instance
  # config_options:
  #   defaults:
  #     interpreter_python: auto_silent
  #     callback_whitelist: profile_tasks, timer, yaml

  name: ansible

That’s a nice solution you guys found… I abhor dealing with venv’s so unless it’s the only possible way, I’m going to keep hoping there’s something even if it’s nested containers.
Speaking of I did spitball something yesterday to a co-worker… Using vscode with the dev-containers extension. The idea is, using an EE as the dev-container image so that way molecule is called inside that container which should then spin up it’s testing container(s).

I guess if you can solve the nested container potential issue it could/should work. If it doesn’t work and you absolutely want to go the container way, why not use the delegated driver and spawn the container on the host (or any host) instead of going DinD ?

I can’t answer your question with any certainty… I’m just not experienced in container environments really much at all yet.