Skip to content

Commit 8d311c3

Browse files
committed
Add a playbook to shutdown all nodes in the cluster
1 parent f8140b5 commit 8d311c3

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
# create kafka server and client instances
3+
- name: shutdown kafka instances
4+
hosts: localhost
5+
vars_files:
6+
- group_vars/kafka/vars
7+
- group_vars/kafka/secret_vars
8+
9+
tasks:
10+
11+
- name: check if hosts are in DNS
12+
# https://galaxy.ansible.com/ui/repo/published/linode/cloud/content/module/domain_info/
13+
linode.cloud.domain_info:
14+
api_token: '{{ api_token }}'
15+
domain: '{{ domain_name }}'
16+
when: domain_name|d(False)
17+
register: domain_info
18+
19+
- name: remove hosts from dns
20+
# https://galaxy.ansible.com/ui/repo/published/linode/cloud/content/module/domain_record/
21+
linode.cloud.domain_record:
22+
api_token: '{{ api_token }}'
23+
domain_id: '{{ domain_info.domain.id }}'
24+
record_id: '{{ record_ids[item.instance.ip_pub1] }}'
25+
state: absent
26+
vars:
27+
record_ids: "{{ dict(domain_info.records | map(attribute='target') | zip(domain_info.records | map(attribute='id'))) }}"
28+
when:
29+
- domain_name|d(False)
30+
- domain_info|d(False)
31+
- item is mapping
32+
- item.instance.ip_pub1 in record_ids
33+
with_items: "{{ kafka_data.server }}"
34+
35+
- name: get list of instances
36+
# https://galaxy.ansible.com/ui/repo/published/linode/cloud/content/module/instance_list/
37+
linode.cloud.instance_list:
38+
api_token: '{{ api_token }}'
39+
filters:
40+
- name: label
41+
values: "{{ [ instance_prefix ] | product(range(1, cluster_size+1)) | map('join') | list }}"
42+
order_by: label
43+
register: existing_instances
44+
45+
- name: shutdown kafka servers
46+
# https://galaxy.ansible.com/ui/repo/published/linode/cloud/content/module/instance/
47+
linode.cloud.instance:
48+
label: '{{ item.label }}'
49+
api_token: '{{ api_token }}'
50+
region: '{{ region }}'
51+
state: absent
52+
with_items: '{{ existing_instances.instances }}'
53+
54+
- name: update group_vars
55+
blockinfile:
56+
path: ./group_vars/kafka/vars
57+
marker: "# {mark} INSTANCE VARS"
58+
state: absent
59+
60+
- name: remove kafka nodes from inventory
61+
blockinfile:
62+
path: ./hosts
63+
marker: "# {mark} KAFKA INSTANCES"
64+
state: absent

0 commit comments

Comments
 (0)