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:
- vpc
Now 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.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/57358115-ad31-4dd6-9fef-e9e4d413f970%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.