build_node_group.yml 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_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. # query asg's and determine if we need to create the others.
  24. # if we find more than 1 for each type, and this isn't an upgrade, then exit
  25. - name: query all asg's for this cluster
  26. ec2_asg_facts:
  27. region: "{{ openshift_aws_region }}"
  28. tags: "{{ {'kubernetes.io/cluster/' ~ openshift_aws_clusterid: openshift_aws_clusterid} | combine(openshift_aws_node_group.tags) }}"
  29. register: asgs
  30. - debug:
  31. msg: "{{ asgs }}"
  32. - fail:
  33. msg: "Found more than 1 auto scaling group that matches the query for group: {{ openshift_aws_node_group }}"
  34. when:
  35. - not openshift_aws_node_group_upgrade
  36. - asgs.results|length > 1
  37. - fail:
  38. msg: "Upgrade: Found more than 2 auto scaling group that matches the query for group: {{ openshift_aws_node_group }}"
  39. when:
  40. - openshift_aws_node_group_upgrade
  41. - asgs.results|length > 2
  42. - name: set the value for the deployment_serial and the current asgs
  43. set_fact:
  44. # scale_groups_serial is a custom filter in role lib_utils
  45. 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) }}"
  46. openshift_aws_current_asgs: "{{ openshift_aws_current_asgs + [asgs.results[0]['auto_scaling_group_name']] if asgs.results else openshift_aws_current_asgs }}"
  47. - name: dump deployment serial
  48. debug:
  49. msg: "Deployment serial: {{ l_deployment_serial }}"
  50. - name: dump current_asgs
  51. debug:
  52. msg: "openshift_aws_current_asgs: {{ openshift_aws_current_asgs }}"
  53. - name: set appropriate vars for upgrade resume
  54. set_fact:
  55. openshift_aws_created_asgs: "{{ [openshift_aws_node_group.name ~ ' ' ~ l_deployment_serial]
  56. | union(openshift_aws_created_asgs) | list }}"
  57. when:
  58. - openshift_aws_node_group_upgrade | default(False)
  59. - asgs.results|length == 2
  60. - when:
  61. - openshift_aws_create_iam_role
  62. - asgs.results|length != 2
  63. include_tasks: iam_role.yml
  64. - when:
  65. - openshift_aws_create_launch_config
  66. - asgs.results|length != 2
  67. include_tasks: launch_config.yml
  68. - when:
  69. - openshift_aws_create_scale_group
  70. - asgs.results|length != 2
  71. include_tasks: scale_group.yml