build_node_group.yml 3.1 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 openshift_aws_node_group.group not in openshift_aws_ami_map) or (openshift_aws_node_group.group in openshift_aws_ami_map and openshift_aws_ami_map[openshift_aws_node_group.group] == '')
  7. block:
  8. - name: fetch recently created AMI
  9. ec2_ami_find:
  10. region: "{{ openshift_aws_region }}"
  11. sort: creationDate
  12. sort_order: descending
  13. name: "{{ openshift_aws_ami_name }}*"
  14. ami_tags: "{{ openshift_aws_ami_tags }}"
  15. no_result_action: fail
  16. register: amiout
  17. - name: Set the openshift_aws_ami
  18. set_fact:
  19. openshift_aws_ami: "{{ amiout.results[0].ami_id }}"
  20. when:
  21. - "'results' in amiout"
  22. - amiout.results|length > 0
  23. # Need to set epoch time in one place to use for launch_config and scale_group
  24. - set_fact:
  25. l_epoch_time: "{{ ansible_date_time.epoch }}"
  26. #
  27. # query asg's and determine if we need to create the others.
  28. # if we find more than 1 for each type, and this isn't an upgrade, then exit
  29. - name: query all asg's for this cluster
  30. ec2_asg_facts:
  31. region: "{{ openshift_aws_region }}"
  32. tags: "{{ {'kubernetes.io/cluster/' ~ openshift_aws_clusterid: openshift_aws_clusterid} | combine(openshift_aws_node_group.tags) }}"
  33. register: asgs
  34. - debug:
  35. msg: "{{ asgs }}"
  36. - fail:
  37. msg: "Found more than 1 auto scaling group that matches the query for group: {{ openshift_aws_node_group }}"
  38. when:
  39. - not openshift_aws_node_group_upgrade
  40. - asgs.results|length > 1
  41. - fail:
  42. msg: "Upgrade: Found more than 2 auto scaling group that matches the query for group: {{ openshift_aws_node_group }}"
  43. when:
  44. - openshift_aws_node_group_upgrade
  45. - asgs.results|length > 2
  46. - name: set the value for the deployment_serial and the current asgs
  47. set_fact:
  48. # scale_groups_serial is a custom filter in role lib_utils
  49. l_deployment_serial: "{{ openshift_aws_node_group_deployment_serial if openshift_aws_node_group_deployment_serial is defined else asgs.results | scale_groups_serial(openshift_aws_node_group_upgrade) }}"
  50. openshift_aws_current_asgs: "{{ openshift_aws_current_asgs + [asgs.results[0]['auto_scaling_group_name']] if asgs.results else openshift_aws_current_asgs }}"
  51. - name: dump deployment serial
  52. debug:
  53. msg: "Deployment serial: {{ l_deployment_serial }}"
  54. - name: dump current_asgs
  55. debug:
  56. msg: "openshift_aws_current_asgs: {{ openshift_aws_current_asgs }}"
  57. - name: set appropriate vars for upgrade resume
  58. set_fact:
  59. openshift_aws_created_asgs: "{{ [openshift_aws_node_group.name ~ ' ' ~ l_deployment_serial]
  60. | union(openshift_aws_created_asgs) | list }}"
  61. when:
  62. - openshift_aws_node_group_upgrade | default(False)
  63. - asgs.results|length == 2
  64. - when:
  65. - openshift_aws_create_iam_role
  66. - asgs.results|length != 2
  67. include_tasks: iam_role.yml
  68. - when:
  69. - openshift_aws_create_launch_config
  70. - asgs.results|length != 2
  71. include_tasks: launch_config.yml
  72. - when:
  73. - openshift_aws_create_scale_group
  74. - asgs.results|length != 2
  75. include_tasks: scale_group.yml