vpc.yml 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. resource_tags:
  39. Name: "{{ item.az }}"
  40. with_items: "{{ openshift_aws_vpc.subnets[openshift_aws_region] }}"
  41. - name: Grab the route tables from our VPC
  42. ec2_vpc_route_table_facts:
  43. region: "{{ openshift_aws_region }}"
  44. filters:
  45. vpc-id: "{{ vpc.vpc.id }}"
  46. register: route_table
  47. - name: update the route table in the vpc
  48. ec2_vpc_route_table:
  49. lookup: id
  50. route_table_id: "{{ route_table.route_tables[0].id }}"
  51. vpc_id: "{{ vpc.vpc.id }}"
  52. region: "{{ openshift_aws_region }}"
  53. tags:
  54. Name: "{{ openshift_aws_vpc_name }}"
  55. routes:
  56. - dest: 0.0.0.0/0
  57. gateway_id: igw
  58. register: route_table_out