Ansible Verifier does not pass its env variables to the verify step
gmuloc opened this issue · 2 comments
gmuloc commented
Issue Type
- Bug report
Molecule and Ansible details
ansible [core 2.12.3]
config file = None
configured module search path = ['/Users/g/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/g/.pyenv/versions/3.10.3/envs/ansible-avd/lib/python3.10/site-packages/ansible
ansible collection location = /Users/g/.ansible/collections:/usr/share/ansible/collections
executable location = /Users/g/.pyenv/versions/ansible-avd/bin/ansible
python version = 3.10.3 (main, Mar 18 2022, 09:31:01) [Clang 13.0.0 (clang-1300.0.29.30)]
jinja version = 3.0.3
libyaml = False
molecule 3.4.1 using python 3.10
ansible:2.12.3
delegated:3.4.1 from molecule
docker:1.1.0 from molecule_docker requiring collections: community.docker>=1.9.1
Molecule installation method (one of):
- pip
Ansible installation method (one of):
- pip
Detail any linters or test runners used:
Desired Behavior
env variables given to the verifier are usable in the verify playbook. i.e. in the output below the debug message should read VERIFIER
Actual Behaviour
Please give some details of what is actually happening.
Include a minimum complete verifiable example with
output of running molecule --debug
.
The current Ansible Verifier is calling the Provisionner verify
function: https://github.com/amarao/molecule/blob/master/src/molecule/verifier/ansible.py#L83. This means that env variables given to the verifier section are not used but rather the ones from the provisionner are:
g% cat molecule/default/molecule.yml
---
dependency:
name: galaxy
driver:
name: delegated
platforms:
- name: instance
provisioner:
name: ansible
env:
DEMO: "PROVISIONER"
verifier:
name: ansible
env:
DEMO: "VERIFIER"
g% cat molecule/default/verify.yml
---
# This is an example playbook to execute Ansible tests.
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Example assertion
debug:
msg: "{{ lookup('env', 'DEMO') }}"
will result in:
g% molecule verify
[...]
PLAY [Verify] ******************************************************************
TASK [Example assertion] *******************************************************
ok: [instance] => {
"msg": "PROVISIONER"
}
zhan9san commented