I have a very simple role called "make_vpc" that creates an EC2 VPC. It takes as inputs three variables: region, vpc_name and vpc_cidr_block.
In my playbook I can just set those variables, call the role, and I get a VPC. It's great!
---
- hosts: localhost
vars:
region: ap-southeast-2
vpc_name: fred
vpc_cidr_block: 10.100.100.0/24
roles:
- vpcNow I want to create a playbook that makes two VPCs, with different names. I want to re-use my role.
How do I do that? How do I provide two sets of variables?
The only way I can think of is to use include_vars inside the role, with the path being based on some variable I set when calling the role.
So in the role I would have:
- include_vars:
file: vars/{{vpc_name}}.yaml
I would make sure that these two files, with appropriate contents, existed:
/path/to/playbook/vars/fred.yaml
/path/to/playbook/vars/mary.yaml
Then in the playbook I would have:
roles:
- { role: vpc, vpc_name: fred }
- [ role: vpc, vpc_name:mary}Is that a good way to do it? Is there a better way?
Regards, K.