3c0636f1561ca80cc90e4d0ac86b05b25608bece
[ta/caas-etcd.git] / ansible / roles / etcd / tasks / main.yml
1 ---
2 # Copyright 2019 Nokia
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 - name: create libs
17   file:
18     name: /var/lib/etcd
19     state: directory
20     owner: caas_etcd
21     group: caas_etcd
22   become_user: "root"
23
24 - set_fact:
25     master_list: "{{ groups.caas_master | list }}"
26
27 - include_tasks: wait_for_etcd.yml
28   with_indexed_items:
29     - "{{ master_list }}"
30   when: ( groups['caas_master']|length|int > 1 ) and ( not nodename | search('caas_master1'))
31
32 - name: template etcd manifest
33   template:
34     src: etcd.yml
35     dest: /etc/kubernetes/manifests/etcd.yml
36   become_user: "root"
37
38 - name: wait for container to start
39   wait_for:
40     host: "{{ ansible_host }}"
41     port: "{{ caas.etcd_api_port }}"
42     state: started
43     timeout: "{{ caas.container_wait_timeout }}"
44   become_user: "root"
45
46 - include_tasks: add_member.yml
47   with_indexed_items:
48     - "{{ hostvars[groups.caas_master[1]]['networking']['infra_internal']['ip'] }}"
49     - "{{ hostvars[groups.caas_master[2]]['networking']['infra_internal']['ip'] }}"
50   when: ( nodename | search("caas_master1") ) and ( groups['caas_master']|length|int > 1 )
51
52 - name: etcd docker id
53   shell: "docker ps --no-trunc | grep etcd | grep -v pause | grep -v grpc-proxy | awk -F' ' '{ print $1 }'"
54   environment:
55     DOCKER_HOST: "tcp://{{ networking.infra_internal.ip }}:2375"
56     DOCKER_TLS_VERIFY: "1"
57     DOCKER_CERT_PATH: "/etc/docker"
58   register: etcd_container_id
59   until: etcd_container_id.stdout
60   delay: 5
61   retries: 60
62
63 - name: sync all etcd
64   shell: "docker exec -t {{ etcd_container_id.stdout }} etcdctl3 member list | grep started | wc -l"
65   environment:
66     DOCKER_HOST: "tcp://{{ networking.infra_internal.ip }}:2375"
67     DOCKER_TLS_VERIFY: "1"
68     DOCKER_CERT_PATH: "/etc/docker"
69   register: result
70   until: result.stdout|int == master_list|length|int
71   delay: 5
72   retries: 100
73