main.yml 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ---
  2. - name: Validate role inputs
  3. fail:
  4. msg: Please ensure to pass the correct variables
  5. when:
  6. - r_openshift_aws_sg_region is undefined
  7. - r_openshift_aws_sg_region is undefined
  8. - name: Fetch the VPC for vpc.id
  9. ec2_vpc_net_facts:
  10. region: "{{ r_openshift_aws_sg_region }}"
  11. filters:
  12. "tag:Name": "{{ r_openshift_aws_sg_clusterid }}"
  13. register: vpcout
  14. - name: Create default security group for cluster
  15. ec2_group:
  16. name: "{{ r_openshift_aws_sg_sg.default.name }}"
  17. description: "{{ r_openshift_aws_sg_sg.default.desc }}"
  18. region: "{{ r_openshift_aws_sg_region }}"
  19. vpc_id: "{{ vpcout.vpcs[0].id }}"
  20. rules: "{{ r_openshift_aws_sg_sg.default.rules | default(omit, True)}}"
  21. register: sg_default_created
  22. - name: create the node group sgs
  23. ec2_group:
  24. name: "{{ item.name}}"
  25. description: "{{ item.desc }}"
  26. rules: "{{ item.rules if 'rules' in item else [] }}"
  27. region: "{{ r_openshift_aws_sg_region }}"
  28. vpc_id: "{{ vpcout.vpcs[0].id }}"
  29. register: sg_create
  30. with_items:
  31. - "{{ r_openshift_aws_sg_sg[r_openshift_aws_sg_type]}}"
  32. - name: create the k8s sgs for the node group
  33. ec2_group:
  34. name: "{{ item.name }}_k8s"
  35. description: "{{ item.desc }} for k8s"
  36. region: "{{ r_openshift_aws_sg_region }}"
  37. vpc_id: "{{ vpcout.vpcs[0].id }}"
  38. register: k8s_sg_create
  39. with_items:
  40. - "{{ r_openshift_aws_sg_sg[r_openshift_aws_sg_type] }}"
  41. - name: tag sg groups with proper tags
  42. ec2_tag:
  43. tags:
  44. KubernetesCluster: "{{ r_openshift_aws_sg_clusterid }}"
  45. resource: "{{ item.group_id }}"
  46. region: "{{ r_openshift_aws_sg_region }}"
  47. with_items: "{{ k8s_sg_create.results }}"