security_group.yml 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ---
  2. - name: Fetch the VPC for the vpc.id
  3. ec2_vpc_net_facts:
  4. region: "{{ openshift_aws_region }}"
  5. filters:
  6. "tag:Name": "{{ openshift_aws_clusterid }}"
  7. register: vpcout
  8. - name: Create default security group for cluster
  9. ec2_group:
  10. name: "{{ openshift_aws_node_security_groups.default.name }}"
  11. description: "{{ openshift_aws_node_security_groups.default.desc }}"
  12. region: "{{ openshift_aws_region }}"
  13. vpc_id: "{{ vpcout.vpcs[0].id }}"
  14. rules: "{{ openshift_aws_node_security_groups.default.rules | default(omit, True)}}"
  15. register: sg_default_created
  16. - name: create the node group sgs
  17. ec2_group:
  18. name: "{{ item.name}}"
  19. description: "{{ item.desc }}"
  20. rules: "{{ item.rules if 'rules' in item else [] }}"
  21. region: "{{ openshift_aws_region }}"
  22. vpc_id: "{{ vpcout.vpcs[0].id }}"
  23. register: sg_create
  24. with_items:
  25. - "{{ openshift_aws_node_security_groups[openshift_aws_node_group_type]}}"
  26. - name: create the k8s sgs for the node group
  27. ec2_group:
  28. name: "{{ item.name }}_k8s"
  29. description: "{{ item.desc }} for k8s"
  30. region: "{{ openshift_aws_region }}"
  31. vpc_id: "{{ vpcout.vpcs[0].id }}"
  32. register: k8s_sg_create
  33. with_items:
  34. - "{{ openshift_aws_node_security_groups[openshift_aws_node_group_type]}}"
  35. - name: tag sg groups with proper tags
  36. ec2_tag:
  37. tags:
  38. KubernetesCluster: "{{ openshift_aws_clusterid }}"
  39. resource: "{{ item.group_id }}"
  40. region: "{{ openshift_aws_region }}"
  41. with_items: "{{ k8s_sg_create.results }}"