Initial commit
[ta/infra-ansible.git] / roles / etcdansible / tasks / handle_reinitialized_etcd.yml
1 # Copyright 2019 Nokia
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 - name: Stop old etcd
16   systemd:
17    name: etcd
18    state: stopped
19   when: reinitialized_nodes is defined and inventory_hostname in reinitialized_nodes
20
21 - name: Remove old etcd directory
22   file:
23       state: absent
24       path: /var/lib/etcd/default.etcd/
25   when: reinitialized_nodes is defined and inventory_hostname in reinitialized_nodes
26
27 - name: Remove and add reinitialized members
28   shell: |
29      echo "{{item.key}}" >> /tmp/out.txt
30      id=$(/bin/etcdctl --endpoints http://{{installation_controller}}:2379 member list | grep "{{item.key}}" | /usr/bin/awk -F[:\[] '{print $1}')
31      if [ $? -eq 0 ]; then
32         /bin/etcdctl --endpoints http://{{installation_controller}}:2379 member remove $id
33      fi
34      /bin/etcdctl --endpoints http://{{installation_controller}}:2379 member add "{{item.key}}" http://"{{hostvars[item.key]['networking']['infra_internal']['ip']}}":2380
35   with_dict: "{{ reinitialized_nodes }}"
36   when: reinitialized_nodes is defined and inventory_hostname == installation_controller and item.key in groups['management']