From 3a349b8519fd4513b3c690571f1f700d6f8714a4 Mon Sep 17 00:00:00 2001 From: Smaine Kahlouch Date: Wed, 16 Dec 2015 21:43:29 +0100 Subject: [PATCH] Using var file for etcd service --- roles/etcd/tasks/configure.yml | 11 ++++------ roles/etcd/templates/etcd2-environment.j2 | 20 ++++++++++++++++++ roles/etcd/templates/etcd2.j2 | 21 ------------------- roles/etcd/templates/systemd-etcd2.service.j2 | 3 +-- 4 files changed, 25 insertions(+), 30 deletions(-) create mode 100644 roles/etcd/templates/etcd2-environment.j2 delete mode 100644 roles/etcd/templates/etcd2.j2 diff --git a/roles/etcd/tasks/configure.yml b/roles/etcd/tasks/configure.yml index 5aea90f44..5d84e0bfc 100644 --- a/roles/etcd/tasks/configure.yml +++ b/roles/etcd/tasks/configure.yml @@ -7,13 +7,10 @@ notify: - restart etcd2 -- name: Create etcd2 environment vars dir - file: path=/etc/systemd/system/etcd2.service.d state=directory - -- name: Write etcd2 config file - template: src=etcd2.j2 dest=/etc/systemd/system/etcd2.service.d/10-etcd2.conf backup=yes - notify: - - restart etcd2 +- name: Create etcd2 environment vars file + template: + src: etcd2-environment.j2 + dest: /etc/etcd2-environment - name: Ensure etcd2 is running service: name=etcd2 state=started enabled=yes diff --git a/roles/etcd/templates/etcd2-environment.j2 b/roles/etcd/templates/etcd2-environment.j2 new file mode 100644 index 000000000..6475e437d --- /dev/null +++ b/roles/etcd/templates/etcd2-environment.j2 @@ -0,0 +1,20 @@ +ETCD_DATA_DIR="/var/lib/etcd2" +{% if inventory_hostname in groups['etcd'] %} +{% set etcd = {} %} +{% for srv in groups['etcd'] %} +{% if inventory_hostname == srv %} +{% set _dummy = etcd.update({'name':"master"+loop.index|string}) %} +{% endif %} +{% endfor %} +ETCD_ADVERTISE_CLIENT_URLS="http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2379" +ETCD_INITIAL_ADVERTISE_PEER_URLS="http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2380" +ETCD_INITIAL_CLUSTER="{% for srv in groups['etcd'] %}master{{ loop.index|string }}=http://{{ srv }}:2380{% if not loop.last %},{% endif %}{% endfor %}" +ETCD_INITIAL_CLUSTER_STATE="new" +ETCD_INITIAL_CLUSTER_TOKEN="k8s_etcd" +ETCD_LISTEN_CLIENT_URLS="http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2379,http://127.0.0.1:2379" +ETCD_LISTEN_PEER_URLS="http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2380" +ETCD_NAME="{{ etcd.name }}" +{% else %} +ETCD_INITIAL_CLUSTER="{% for srv in groups['etcd'] %}master{{ loop.index|string }}=http://{{ srv }}:2380{% if not loop.last %},{% endif %}{% endfor %}" +ETCD_LISTEN_CLIENT_URLS="http://127.0.0.1:23799" +{% endif %} diff --git a/roles/etcd/templates/etcd2.j2 b/roles/etcd/templates/etcd2.j2 deleted file mode 100644 index a00fb72e2..000000000 --- a/roles/etcd/templates/etcd2.j2 +++ /dev/null @@ -1,21 +0,0 @@ -# etcd2.0 -[Service] -{% if inventory_hostname in groups['etcd'] %} -{% set etcd = {} %} -{% for srv in groups['etcd'] %} -{% if inventory_hostname == srv %} -{% set _dummy = etcd.update({'name':"master"+loop.index|string}) %} -{% endif %} -{% endfor %} -Environment="ETCD_ADVERTISE_CLIENT_URLS=http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2379" -Environment="ETCD_INITIAL_ADVERTISE_PEER_URLS=http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2380" -Environment="ETCD_INITIAL_CLUSTER={% for srv in groups['etcd'] %}master{{ loop.index|string }}=http://{{ srv }}:2380{% if not loop.last %},{% endif %}{% endfor %}" -Environment="ETCD_INITIAL_CLUSTER_STATE=new" -Environment="ETCD_INITIAL_CLUSTER_TOKEN=k8s_etcd" -Environment="ETCD_LISTEN_CLIENT_URLS=http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2379,http://127.0.0.1:2379" -Environment="ETCD_LISTEN_PEER_URLS=http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2380" -Environment="ETCD_NAME={{ etcd.name }}" -{% else %} -Environment="ETCD_INITIAL_CLUSTER={% for srv in groups['etcd'] %}master{{ loop.index|string }}=http://{{ srv }}:2380{% if not loop.last %},{% endif %}{% endfor %}" -Environment="ETCD_LISTEN_CLIENT_URLS=http://127.0.0.1:23799" -{% endif %} diff --git a/roles/etcd/templates/systemd-etcd2.service.j2 b/roles/etcd/templates/systemd-etcd2.service.j2 index 84a527d04..ca6d37676 100644 --- a/roles/etcd/templates/systemd-etcd2.service.j2 +++ b/roles/etcd/templates/systemd-etcd2.service.j2 @@ -4,8 +4,7 @@ Conflicts=etcd.service [Service] User=etcd -Environment=ETCD_DATA_DIR=/var/lib/etcd2 -Environment=ETCD_NAME=%m +EnvironmentFile=/etc/etcd2-environment {% if inventory_hostname in groups['etcd'] %} ExecStart={{ bin_dir }}/etcd2 {% else %}