vpc.yml 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ---
  2. - name: query azs
  3. aws_az_facts:
  4. region: "{{ openshift_aws_region }}"
  5. register: azs
  6. - fail:
  7. msg: >
  8. AWS VPC does NOT contain
  9. {{ openshift_aws_vpc.subnets[openshift_aws_region] | map(attribute='az') | list | length }} availability zone(s).
  10. Please pick another region!
  11. when:
  12. - ( azs.availability_zones | length ) < ( openshift_aws_vpc.subnets[openshift_aws_region] | map(attribute='az') | list | length )
  13. - name: Create AWS VPC
  14. ec2_vpc_net:
  15. state: present
  16. cidr_block: "{{ openshift_aws_vpc.cidr }}"
  17. dns_support: True
  18. dns_hostnames: True
  19. region: "{{ openshift_aws_region }}"
  20. name: "{{ openshift_aws_clusterid }}"
  21. tags: "{{ openshift_aws_vpc_tags }}"
  22. register: vpc
  23. - name: Sleep to avoid a race condition when creating the vpc
  24. pause:
  25. seconds: 5
  26. when: vpc.changed
  27. - name: assign the vpc igw
  28. ec2_vpc_igw:
  29. region: "{{ openshift_aws_region }}"
  30. vpc_id: "{{ vpc.vpc.id }}"
  31. register: igw
  32. - name: assign the vpc subnets
  33. ec2_vpc_subnet:
  34. region: "{{ openshift_aws_region }}"
  35. vpc_id: "{{ vpc.vpc.id }}"
  36. cidr: "{{ item.cidr }}"
  37. az: "{{ item.az }}"
  38. with_items: "{{ openshift_aws_vpc.subnets[openshift_aws_region] }}"
  39. - name: Grab the route tables from our VPC
  40. ec2_vpc_route_table_facts:
  41. region: "{{ openshift_aws_region }}"
  42. filters:
  43. vpc-id: "{{ vpc.vpc.id }}"
  44. register: route_table
  45. - name: update the route table in the vpc
  46. ec2_vpc_route_table:
  47. lookup: id
  48. route_table_id: "{{ route_table.route_tables[0].id }}"
  49. vpc_id: "{{ vpc.vpc.id }}"
  50. region: "{{ openshift_aws_region }}"
  51. tags:
  52. Name: "{{ openshift_aws_vpc_name }}"
  53. routes:
  54. - dest: 0.0.0.0/0
  55. gateway_id: igw
  56. register: route_table_out