Closed decentral1se closed 3 years ago
I have been using j2cli for this purpose.
Since I want to use the goss test anyway in production, I have it as a template and the vars in default/main.yml
I can then update my development goss tests by running (e.g. in nginx role)
j2 --customize ~/custom-j2.py templates/test_nginx.yml.j2 defaults/main.yml > molecule/default/tests/test_default.yml
We just need to adapt j2cli
to the ansible jinja2 config
# custom-j2.py
def j2_environment_params():
""" Extra parameters for the Jinja2 Environment """
# Jinja2 Environment configuration
# http://jinja.pocoo.org/docs/2.10/api/#jinja2.Environment
return dict(
# Remove whitespace around blocks
trim_blocks=True,
)
Does this somehow help? Can it be integrated into molecule?
@t2d have you got a working example on Github that we can take a look at please ?
Would it be a good idea to put a verifier task as a yml file inside role tasks? Then you can execute it with molecule verify.yml. In that way you could access inventory and role vars. Also run it in other deployments.
@decentral1se I think it's possible this request was addressed by @markwell-ch via PR #13
Can you verify?
Awesome, that works like a charm! https://github.com/systemli/ansible-role-sshd/commit/abc61369364d42416e4958d18da6e705985250d0 Thanks @markwell-ch !
Transferring https://github.com/ansible/molecule/issues/2375 to here.
We need to pass the role
defaults/main.yml
andvars/main.yml
into the verifier (like goss). If I have in mydefaults/main.yml
:And then a Goss test like:
My tests and my vars can quickly get out of sync when I change my vars.
How can we receive vars from Ansible in the context of Molecule?