/test/integration/roles/test_ec2_elb/tasks/main.yml

https://github.com/ajanthanm/ansible · YAML · 188 lines · 144 code · 27 blank · 17 comment · 0 complexity · 1258f48e7123495459ec5ac740debf87 MD5 · raw file

  1. ---
  2. # tasks file for test_ec2_elb
  3. # ============================================================
  4. # create an ELB for testing
  5. - name: create the test load balancer
  6. ec2_elb_lb:
  7. name: "{{ resource_prefix }}"
  8. ec2_access_key: "{{ ec2_access_key }}"
  9. ec2_secret_key: "{{ ec2_secret_key }}"
  10. region: "{{ ec2_region }}"
  11. state: present
  12. zones:
  13. - "{{ ec2_region }}b"
  14. - "{{ ec2_region }}c"
  15. listeners:
  16. - protocol: http
  17. load_balancer_port: 80
  18. instance_port: 80
  19. health_check:
  20. ping_protocol: http
  21. ping_port: 80
  22. ping_path: "/index.html"
  23. response_timeout: 5
  24. interval: 10
  25. unhealthy_threshold: 3
  26. healthy_threshold: 2
  27. register: result
  28. - name: assert the test load balancer was created correctly
  29. assert:
  30. that:
  31. - 'result.changed'
  32. - '"failed" not in result'
  33. - 'result.elb.status == "created"'
  34. - '"{{ ec2_region }}b" in result.elb.zones'
  35. - '"{{ ec2_region }}c" in result.elb.zones'
  36. - 'result.elb.health_check.healthy_threshold == 2'
  37. - 'result.elb.health_check.interval == 10'
  38. - 'result.elb.health_check.target == "HTTP:80/index.html"'
  39. - 'result.elb.health_check.timeout == 5'
  40. - 'result.elb.health_check.unhealthy_threshold == 3'
  41. - '[80, 80, "HTTP", "HTTP"] in result.elb.listeners'
  42. # ============================================================
  43. # add one of the instances to the LB
  44. - name: add first instance to the load balancer
  45. ec2_elb:
  46. ec2_elbs: "{{ resource_prefix }}"
  47. ec2_access_key: "{{ ec2_access_key }}"
  48. ec2_secret_key: "{{ ec2_secret_key }}"
  49. region: "{{ ec2_region }}"
  50. instance_id: "{{ ec2_provision_result.instance_ids[0] }}"
  51. state: present
  52. wait_timeout: 300
  53. register: result
  54. - name: assert the first instance was added ok
  55. assert:
  56. that:
  57. - 'result.changed == True'
  58. - '"{{resource_prefix}}" in result.ansible_facts.ec2_elbs'
  59. # ============================================================
  60. # add all other instances to the LB
  61. - name: add other instances to the load balancer
  62. ec2_elb:
  63. ec2_elbs: "{{ resource_prefix }}"
  64. ec2_access_key: "{{ ec2_access_key }}"
  65. ec2_secret_key: "{{ ec2_secret_key }}"
  66. region: "{{ ec2_region }}"
  67. instance_id: "{{ item }}"
  68. state: present
  69. wait_timeout: 300
  70. with_items: "ec2_provision_result.instance_ids[1:]"
  71. register: result
  72. - name: assert the other instances were added ok
  73. assert:
  74. that:
  75. - 'item.changed == True'
  76. - '"{{resource_prefix}}" in item.ansible_facts.ec2_elbs'
  77. with_items: result.results
  78. # ============================================================
  79. # shutdown http first instance so it goes out of service
  80. - name: "shutdown the apache service on the first instance ({{ec2_provision_result.instances[0].public_ip}})"
  81. service: name=httpd state=stopped
  82. remote_user: "ec2-user"
  83. sudo: yes
  84. sudo_user: root
  85. delegate_to: "{{ec2_provision_result.instances[0].public_ip}}"
  86. - name: assert that the httpd service was stopped
  87. assert:
  88. that:
  89. - 'result.changed == True'
  90. - name: pause long enough for the instance to go out of service
  91. pause: seconds=60
  92. # ============================================================
  93. # remove the out of service instance
  94. - name: remove the out of service instance
  95. ec2_elb:
  96. ec2_elbs: "{{ resource_prefix }}"
  97. ec2_access_key: "{{ ec2_access_key }}"
  98. ec2_secret_key: "{{ ec2_secret_key }}"
  99. region: "{{ ec2_region }}"
  100. instance_id: "{{ ec2_provision_result.instance_ids[0] }}"
  101. state: absent
  102. wait_timeout: 300
  103. register: result
  104. - name: assert that the out of service instance was removed
  105. assert:
  106. that:
  107. - 'result.changed == True'
  108. - '"{{resource_prefix}}" in result.ansible_facts.ec2_elbs'
  109. # ============================================================
  110. # remove another instance that is still in service
  111. - name: remove the second instance
  112. ec2_elb:
  113. ec2_elbs: "{{ resource_prefix }}"
  114. ec2_access_key: "{{ ec2_access_key }}"
  115. ec2_secret_key: "{{ ec2_secret_key }}"
  116. region: "{{ ec2_region }}"
  117. instance_id: "{{ ec2_provision_result.instance_ids[1] }}"
  118. state: absent
  119. wait_timeout: 300
  120. register: result
  121. - name: assert that the second instance was removed
  122. assert:
  123. that:
  124. - 'result.changed == True'
  125. - '"{{resource_prefix}}" in result.ansible_facts.ec2_elbs'
  126. # ============================================================
  127. # re-register the second instance (issue #4902)
  128. - name: re-register the second instance (issue #4902)
  129. ec2_elb:
  130. ec2_elbs: "{{ resource_prefix }}"
  131. ec2_access_key: "{{ ec2_access_key }}"
  132. ec2_secret_key: "{{ ec2_secret_key }}"
  133. region: "{{ ec2_region }}"
  134. instance_id: "{{ ec2_provision_result.instance_ids[1] }}"
  135. state: present
  136. wait_timeout: 300
  137. register: result
  138. - name: assert the instance was re-registered ok
  139. assert:
  140. that:
  141. - 'result.changed == True'
  142. - '"{{resource_prefix}}" in result.ansible_facts.ec2_elbs'
  143. # ============================================================
  144. # remove all other instances
  145. - name: remove the rest of the instances
  146. ec2_elb:
  147. ec2_elbs: "{{ resource_prefix }}"
  148. ec2_access_key: "{{ ec2_access_key }}"
  149. ec2_secret_key: "{{ ec2_secret_key }}"
  150. region: "{{ ec2_region }}"
  151. instance_id: "{{ item }}"
  152. state: absent
  153. wait_timeout: 300
  154. with_items: "ec2_provision_result.instance_ids[1:]"
  155. register: result
  156. - name: assert the other instances were removed
  157. assert:
  158. that:
  159. - 'item.changed == True'
  160. - '"{{resource_prefix}}" in item.ansible_facts.ec2_elbs'
  161. with_items: result.results