Initial commit
[ta/infra-ansible.git] / roles / etcdansible / tasks / handle_reinitialized_etcd.yml
diff --git a/roles/etcdansible/tasks/handle_reinitialized_etcd.yml b/roles/etcdansible/tasks/handle_reinitialized_etcd.yml
new file mode 100644 (file)
index 0000000..1ca76de
--- /dev/null
@@ -0,0 +1,36 @@
+# Copyright 2019 Nokia
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+- name: Stop old etcd
+  systemd:
+   name: etcd
+   state: stopped
+  when: reinitialized_nodes is defined and inventory_hostname in reinitialized_nodes
+
+- name: Remove old etcd directory
+  file:
+      state: absent
+      path: /var/lib/etcd/default.etcd/
+  when: reinitialized_nodes is defined and inventory_hostname in reinitialized_nodes
+
+- name: Remove and add reinitialized members
+  shell: |
+     echo "{{item.key}}" >> /tmp/out.txt
+     id=$(/bin/etcdctl --endpoints http://{{installation_controller}}:2379 member list | grep "{{item.key}}" | /usr/bin/awk -F[:\[] '{print $1}')
+     if [ $? -eq 0 ]; then
+        /bin/etcdctl --endpoints http://{{installation_controller}}:2379 member remove $id
+     fi
+     /bin/etcdctl --endpoints http://{{installation_controller}}:2379 member add "{{item.key}}" http://"{{hostvars[item.key]['networking']['infra_internal']['ip']}}":2380
+  with_dict: "{{ reinitialized_nodes }}"
+  when: reinitialized_nodes is defined and inventory_hostname == installation_controller and item.key in groups['management']