PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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