vpc.yml 1.7 KB

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