|
1 | 1 | ---
|
2 | 2 | # This role contains tasks for configuring and starting etcd service
|
3 | 3 |
|
4 |
| -- name: download etcdctl {{ etcd_version }} |
5 |
| - get_url: |
6 |
| - validate_certs: "{{ validate_certs }}" |
7 |
| - url: https://github.com/coreos/etcd/releases/download/{{ etcd_version }}/etcd-{{ etcd_version }}-linux-amd64.tar.gz |
8 |
| - dest: /tmp/etcd-{{ etcd_version }}-linux-amd64.tar.gz |
9 |
| - tags: |
10 |
| - - prebake-for-dev |
11 |
| - |
12 |
| -- name: install etcdctl |
13 |
| - shell: > |
14 |
| - tar vxzf /tmp/etcd-{{ etcd_version }}-linux-amd64.tar.gz && \ |
15 |
| - mv etcd-{{ etcd_version }}-linux-amd64/etcd* /usr/bin |
16 |
| - tags: |
17 |
| - - prebake-for-dev |
18 |
| - |
19 |
| -- name: install etcd {{ etcd_version }} |
20 |
| - shell: docker pull quay.io/coreos/etcd:{{ etcd_version }} |
21 |
| - tags: |
22 |
| - - prebake-for-dev |
23 |
| - |
24 |
| -- name: setup iptables for etcd |
25 |
| - shell: > |
26 |
| - ( iptables -L INPUT | grep "{{ etcd_rule_comment }} ({{ item }})" ) || \ |
27 |
| - iptables -I INPUT 1 -p tcp --dport {{ item }} -j ACCEPT -m comment --comment "{{ etcd_rule_comment }} ({{ item }})" |
28 |
| - become: true |
29 |
| - with_items: |
30 |
| - - "{{ etcd_client_port1 }}" |
31 |
| - - "{{ etcd_client_port2 }}" |
32 |
| - - "{{ etcd_peer_port1 }}" |
33 |
| - - "{{ etcd_peer_port2 }}" |
34 |
| - |
35 |
| -- name: copy the etcd start/stop script |
36 |
| - template: src=etcd.j2 dest=/usr/bin/etcd.sh mode=u=rwx,g=rx,o=rx |
37 |
| - |
38 |
| -- name: copy systemd units for etcd |
39 |
| - copy: src=etcd.service dest=/etc/systemd/system/etcd.service |
40 |
| - |
41 |
| -- name: start etcd |
42 |
| - systemd: name=etcd daemon_reload=yes state=started enabled=yes |
43 |
| - |
| 4 | +- block: |
| 5 | + - name: download etcdctl {{ etcd_version }} |
| 6 | + get_url: |
| 7 | + validate_certs: "{{ validate_certs }}" |
| 8 | + url: https://github.com/coreos/etcd/releases/download/{{ etcd_version }}/etcd-{{ etcd_version }}-linux-amd64.tar.gz |
| 9 | + dest: /tmp/etcd-{{ etcd_version }}-linux-amd64.tar.gz |
| 10 | + tags: |
| 11 | + - prebake-for-dev |
| 12 | + |
| 13 | + - name: install etcdctl binaries |
| 14 | + shell: > |
| 15 | + tar vxzf /tmp/etcd-{{ etcd_version }}-linux-amd64.tar.gz && |
| 16 | + mv etcd-{{ etcd_version }}-linux-amd64/etcd* /usr/bin |
| 17 | + tags: |
| 18 | + - prebake-for-dev |
| 19 | + |
| 20 | + - name: pull etcd container {{ etcd_version }} |
| 21 | + shell: docker pull quay.io/coreos/etcd:{{ etcd_version }} |
| 22 | + tags: |
| 23 | + - prebake-for-dev |
| 24 | + |
| 25 | + - name: setup iptables for etcd |
| 26 | + shell: > |
| 27 | + ( iptables -L INPUT | grep "{{ etcd_rule_comment }} ({{ item }})" ) || \ |
| 28 | + iptables -I INPUT 1 -p tcp --dport {{ item }} -j ACCEPT -m comment --comment "{{ etcd_rule_comment }} ({{ item }})" |
| 29 | + become: true |
| 30 | + with_items: |
| 31 | + - "{{ etcd_client_port1 }}" |
| 32 | + - "{{ etcd_client_port2 }}" |
| 33 | + - "{{ etcd_peer_port1 }}" |
| 34 | + |
| 35 | + - name: Set facts from role defaults for sharing with other hosts |
| 36 | + set_fact: |
| 37 | + etcd_node_name: "{{ etcd_node_name }}" |
| 38 | + etcd_peer_advertise_urls: "{{ etcd_peer_advertise_urls }}" |
| 39 | + |
| 40 | + - name: template etcd docker environment file |
| 41 | + template: |
| 42 | + src: etcd_env_file.j2 |
| 43 | + dest: "/etc/{{ etcd_service_name }}.env" |
| 44 | + |
| 45 | + - name: template systemd units for etcd |
| 46 | + template: |
| 47 | + src: etcd.service.j2 |
| 48 | + dest: "/etc/systemd/system/{{ etcd_service_name }}.service" |
| 49 | + |
| 50 | + - name: start etcd server or proxy |
| 51 | + systemd: |
| 52 | + name: "{{ etcd_service_name }}" |
| 53 | + daemon_reload: yes |
| 54 | + state: started |
| 55 | + enabled: yes |
| 56 | + when: etcd_member|bool or etcd_proxy|bool |
0 commit comments