provision_ec2_facts.yml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ---
  2. # When openshift_aws_use_custom_ami is '' then
  3. # we retrieve the latest build AMI.
  4. # Then set openshift_aws_ami to the ami.
  5. - when:
  6. - (openshift_aws_ami == '' and 'master' not in openshift_aws_ami_map) or ('master' in openshift_aws_ami_map and openshift_aws_ami_map['master'] == '')
  7. block:
  8. - name: fetch recently created AMI
  9. ec2_ami_facts:
  10. region: "{{ openshift_aws_region }}"
  11. filters: "{ 'name': '{{ openshift_aws_ami_name }}*',
  12. {%- for key in openshift_aws_ami_tags -%}
  13. 'tag:{{ key }}': '{{ openshift_aws_ami_tags[key] }}',
  14. {%- endfor -%} }"
  15. register: amiout
  16. failed_when: "amiout.images|length == 0"
  17. - name: Set the openshift_aws_ami
  18. set_fact:
  19. openshift_aws_ami: "{{ ( amiout.images | sort(attribute='creation_date') | map(attribute='image_id') | reverse | list )[0] }}"
  20. when:
  21. - "'images' in amiout"
  22. - amiout.images|length > 0
  23. - block:
  24. # query instance's and determine if we need to create the others.
  25. # if we find more than 1 for each type, and this isn't an upgrade, then exit
  26. - name: fetch all master ec2s for this cluster
  27. ec2_instance_facts:
  28. region: "{{ openshift_aws_region }}"
  29. filters:
  30. instance-state-name: running
  31. vpc-id: "{{ vpcout.vpcs.0.id }}"
  32. "tag:clusterid": "{{ openshift_aws_clusterid }}"
  33. "tag:host-type": "master"
  34. register: ec2s
  35. - debug:
  36. msg: "{{ ec2s.instances }}"
  37. - fail:
  38. msg: "Found more than 1 group that matches the query for group: master"
  39. when:
  40. - not openshift_aws_node_group_upgrade
  41. - ( ec2s.instances | map(attribute='tags.deployment_serial') | list | unique | count ) > 1
  42. - fail:
  43. msg: "Upgrade: Found more than 2 groups that matches the query for group: master"
  44. when:
  45. - openshift_aws_node_group_upgrade
  46. - asgs.results|length > 2
  47. - name: Modify ec2 tags dictionary
  48. set_fact:
  49. ec2s: "{{ ec2s.instances | map(attribute='tags') | list | unique | ec2_to_asg_tag }}"
  50. - name: set the value for the deployment_serial
  51. set_fact:
  52. # scale_groups_serial is a custom filter in role lib_utils
  53. l_deployment_serial: "{{ openshift_aws_node_group_deployment_serial if openshift_aws_node_group_deployment_serial is defined else ec2s | scale_groups_serial(openshift_aws_node_group_upgrade) }}"
  54. - name: dump deployment serial
  55. debug:
  56. msg: "Deployment serial: {{ l_deployment_serial }}"
  57. - set_fact:
  58. l_instance_tags: "{{ openshift_aws_node_group_config_tags
  59. | combine((openshift_aws_master_group | selectattr('group', 'match', 'master') | list | first).tags)
  60. | combine({'deployment_serial': l_deployment_serial, 'ami': openshift_aws_ami_map['master'] | default(openshift_aws_ami)})
  61. | combine({'openshift-node-group-config': (openshift_aws_master_group | selectattr('group', 'match', 'master') | list | first).node_group_config | default('unset') }) }}"
  62. l_image: "{{ openshift_aws_ami_map['master'] | default(openshift_aws_ami) }}"
  63. - name: subnets
  64. set_fact:
  65. l_subnetout_results: "{{ openshift_aws_master_instance_config.exact_count | subnet_count_list(subnetout.results) }}"
  66. - name: dump subnet count
  67. debug:
  68. msg: "subnet count: {{ l_subnetout_results }}"
  69. - name: fetch the security groups
  70. ec2_group_facts:
  71. filters:
  72. group-name: "{{ openshift_aws_master_instance_config.groups }}"
  73. vpc-id: "{{ vpcout.vpcs[0].id }}"
  74. region: "{{ openshift_aws_region }}"
  75. register: ec2sgs