|
| 1 | +--- |
| 2 | +# shutdown 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 | + # DNS |
| 12 | + |
| 13 | + - name: check if hosts are in DNS |
| 14 | + # https://galaxy.ansible.com/ui/repo/published/linode/cloud/content/module/domain_info/ |
| 15 | + linode.cloud.domain_info: |
| 16 | + api_token: '{{ api_token }}' |
| 17 | + domain: '{{ domain_name }}' |
| 18 | + when: domain_name|d(False) |
| 19 | + register: domain_info |
| 20 | + |
| 21 | + - name: remove hosts from dns |
| 22 | + # https://galaxy.ansible.com/ui/repo/published/linode/cloud/content/module/domain_record/ |
| 23 | + linode.cloud.domain_record: |
| 24 | + api_token: '{{ api_token }}' |
| 25 | + domain_id: '{{ domain_info.domain.id }}' |
| 26 | + record_id: '{{ item.id }}' |
| 27 | + state: absent |
| 28 | + when: |
| 29 | + - domain_name|d(False) |
| 30 | + - domain_info|d(False) |
| 31 | + - item.target in (kafka_data.server | map(attribute='instance.ip_pub1')) |
| 32 | + with_items: "{{ domain_info.records }}" |
| 33 | + |
| 34 | + |
| 35 | + # Instances |
| 36 | + |
| 37 | + - name: get list of instances |
| 38 | + # https://galaxy.ansible.com/ui/repo/published/linode/cloud/content/module/instance_list/ |
| 39 | + linode.cloud.instance_list: |
| 40 | + api_token: '{{ api_token }}' |
| 41 | + filters: |
| 42 | + - name: label |
| 43 | + values: "{{ [ instance_prefix ] | product(range(1, cluster_size+1)) | map('join') | list }}" |
| 44 | + order_by: label |
| 45 | + register: existing_instances |
| 46 | + |
| 47 | + - name: shutdown kafka servers |
| 48 | + # https://galaxy.ansible.com/ui/repo/published/linode/cloud/content/module/instance/ |
| 49 | + linode.cloud.instance: |
| 50 | + label: '{{ item.label }}' |
| 51 | + api_token: '{{ api_token }}' |
| 52 | + region: '{{ region }}' |
| 53 | + state: absent |
| 54 | + with_items: '{{ existing_instances.instances }}' |
| 55 | + |
| 56 | + - name: update group_vars |
| 57 | + blockinfile: |
| 58 | + path: ./group_vars/kafka/vars |
| 59 | + marker: "# {mark} INSTANCE VARS" |
| 60 | + state: absent |
| 61 | + |
| 62 | + - name: remove kafka nodes from inventory |
| 63 | + blockinfile: |
| 64 | + path: ./hosts |
| 65 | + marker: "# {mark} KAFKA INSTANCES" |
| 66 | + state: absent |
0 commit comments