Replies: 2 comments 2 replies
-
If going the multiple scenario route another idea would be to parameterize your scenario from outside with environment variables and stick with one scenario
in your molecule.yml you would have
you could also put the shell variable in an env file.
Another method is using one scenario with multiple platforms, but that does not scale well with big N. |
Beta Was this translation helpful? Give feedback.
-
You can put your base config into your project's The problem with defining your platform there is that once you override any parameters, you end up having to override the whole thing anyway :/ We also run multiple systems in parallel in CI. An example of our scenario-specific platform config looks like (don't sweat the non-standard parameters, we created our own ec2-driver create/destroy scenarios: platforms:
- name: '${MOLECULE_SCENARIO_NAME}-${PLAYBOOK_NAME}-${MOLECULE_ANSIBLE_VERSION:-localtest}'
region: ${AWS_REGION}
vpc_id: ${AWS_VPC_ID}
vpc_subnet_id: ${AWS_SUBNET}
instance_type: ${AWS_INSTANCE_TYPE}
security_groups: ${AWS_SECURITY_GROUPS}
aws_iam_role: ${AWS_IAM_ROLE}
tags:
project_id: enterprise
molecule_pipeline_id: ${CI_PIPELINE_ID:-manual}
ansible_managed: 'true'
Name: Ansible Molecule - ${MOLECULE_SCENARIO_NAME}-${PLAYBOOK_NAME}-${MOLECULE_ANSIBLE_VERSION:-localtest}
image: ${AWS_AMI_RHEL_9}
key_inject_method: ec2
groups:
- account_development
- os_rhel_9
- aws_ec2
- molecule
- vault_molecule
- hashicorp_vault_molecule
- all The only difference between the scanerio platforms is the groups parameter. Everything else is (or should be) either dynamically set via the .env file in the root project directory or driven by the parallel matrix variables in our GitLab ci. So if we didn't have to define the entire platform due to how Ansible merges dictionaries, we could just get away with: platforms:
groups:
- account_development
- os_rhel_9
- aws_ec2
- molecule
- vault_molecule
- hashicorp_vault_molecule
- all But I don't think the merging is additive, so we do have to redefine the whole thing. Someone please let me know if I'm wrong. I'll actually play with this today to see if I am ;) |
Beta Was this translation helpful? Give feedback.
-
I've got a role I want to call
N
times with different parameters on a fixed set of hosts and test/verify the different outcomes.It is my understanding, that I have to use
N
different scenarios for this, calling the role with according parameters inconverge.yml
and verifying the outcomes inverify.yml
Every parameter - except the scenario name - in
molecule.yml
of each scenario is exactly the same, as far as I am concerned, though I can't be sure, because I had to copy themN
times, make some adjustments, like adding another platform/host, and may have forgotten to adjust some of them.To avoid problems like this which are ultimately the result of unnecessary duplication I would like to share the
platforms
& other parameters between theseN
scenarios.I found in the documentation, that for
inventory
I could use thelinks
parameter.But how would I do that for
platforms
and maybe other parameters? Searches in documentation and the web have been fruitless to the day.Or maybe I'm wrong in using multiple scenarios?
Beta Was this translation helpful? Give feedback.
All reactions