The VPC role

The first role we are going to create is the one which creates the VPC itself. Everything we are going to configure/create in the upcoming roles needs to be hosted within a VPC, so it needs to be created and then we need to gather some information on it so we can proceed with the rest of the playbook.

To bootstrap the role, run the following command from within your working folder:

$ ansible-galaxy init roles/vpc

Now that we have the files for the role, open roles/vpc/tasks/main.yml and enter the following:

- name: ensure that the VPC is present  ec2_vpc_net:    region: "{{ ec2_region }}"    name: "{{ environment_name }}"    state: present    cidr_block: "{{ vpc_cidr_block }}" resource_tags: { "Name" : "{{ environment_name }}", "Environment" ...

Get Learn Ansible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.