|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +# contributor license agreements. See the NOTICE file distributed with |
| 4 | +# this work for additional information regarding copyright ownership. |
| 5 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +# (the "License"); you may not use this file except in compliance with |
| 7 | +# the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +--- |
| 18 | +# This role will install etcd in group 'etcd' in the environment inventory |
| 19 | + |
| 20 | +- name: "Set the name of the etcd node" |
| 21 | + set_fact: |
| 22 | + name: "etcd{{ groups['etcd'].index(inventory_hostname) }}" |
| 23 | + |
| 24 | +- name: "set the volume_dir" |
| 25 | + set_fact: |
| 26 | + volume_dir: "{{ etcd.dir.data }}/etcd{{ groups['etcd'].index(inventory_hostname) }}:/etcd-data" |
| 27 | + when: etcd_data_dir is defined |
| 28 | + |
| 29 | + |
| 30 | +- name: "Set the cluster of the etcd cluster" |
| 31 | + set_fact: |
| 32 | + cluster: "{% set etcdhosts = [] %} |
| 33 | + {% for host in groups['etcd'] %} |
| 34 | + {{ etcdhosts.append('etcd' + ((loop.index-1)|string) + '=' + 'http://' + hostvars[host].ansible_host + ':' + ((2480+loop.index-1)|string) ) }} |
| 35 | + {% endfor %} |
| 36 | + {{ etcdhosts | join(',') }}" |
| 37 | + |
| 38 | +- name: (re)start etcd |
| 39 | + docker_container: |
| 40 | + name: etcd{{ groups['etcd'].index(inventory_hostname) }} |
| 41 | + image: quay.io/coreos/etcd:{{ etcd.version }} |
| 42 | + state: started |
| 43 | + recreate: true |
| 44 | + restart_policy: "{{ docker.restart.policy }}" |
| 45 | + volumes: "{{volume_dir | default([])}}" |
| 46 | + command: "/usr/local/bin/etcd \ |
| 47 | + --data-dir=/etcd-data --name '{{ name }}' \ |
| 48 | + --initial-advertise-peer-urls http://{{ ansible_host }}:{{ etcd.server.port + groups['etcd'].index(inventory_hostname) }} \ |
| 49 | + --advertise-client-urls http://{{ ansible_host }}:{{ etcd.client.port + groups['etcd'].index(inventory_hostname) }} \ |
| 50 | + --listen-peer-urls http://0.0.0.0:{{ etcd.server.port + groups['etcd'].index(inventory_hostname) }} \ |
| 51 | + --listen-client-urls http://0.0.0.0:{{ etcd.client.port + groups['etcd'].index(inventory_hostname) }} \ |
| 52 | + --initial-cluster {{ cluster }} \ |
| 53 | + --initial-cluster-state new --initial-cluster-token {{ etcd.cluster.token }} \ |
| 54 | + --quota-backend-bytes {{ etcd.quota_backend_bytes }} \ |
| 55 | + --snapshot-count {{ etcd.snapshot_count }} \ |
| 56 | + --auto-compaction-retention {{ etcd.auto_compaction_retention }} \ |
| 57 | + --auto-compaction-mode {{ etcd.auto_compaction_mode }} \ |
| 58 | + --log-level {{ etcd.loglevel }}" |
| 59 | + ports: |
| 60 | + - "{{ etcd.client.port + groups['etcd'].index(inventory_hostname) }}:{{ etcd.client.port + groups['etcd'].index(inventory_hostname) }}" |
| 61 | + - "{{ etcd.server.port + groups['etcd'].index(inventory_hostname) }}:{{ etcd.server.port + groups['etcd'].index(inventory_hostname) }}" |
| 62 | + pull: "{{ etcd.pull_etcd | default(true) }}" |
| 63 | + |
| 64 | +- name: wait until etcd in this host is up and running |
| 65 | + uri: |
| 66 | + url: "http://{{ ansible_host }}:{{ etcd.client.port + groups['etcd'].index(inventory_hostname) }}/health" |
| 67 | + register: result |
| 68 | + until: result.status == 200 |
| 69 | + retries: 12 |
| 70 | + delay: 5 |
0 commit comments