From b66cc67b6f0321e24618e0921ead4d29622188c3 Mon Sep 17 00:00:00 2001
From: Smaine Kahlouch <smaine.kahlouch@arkena.com>
Date: Fri, 11 Dec 2015 11:44:41 +0100
Subject: [PATCH] Configure network-environment with a single template

---
 roles/network_plugin/tasks/flannel.yml        |  4 --
 roles/network_plugin/tasks/main.yml           |  7 ++--
 .../templates/flannel/network-environment.j2  |  1 -
 .../{calico => }/network-environment.j2       | 42 ++++++++++---------
 4 files changed, 26 insertions(+), 28 deletions(-)
 delete mode 100644 roles/network_plugin/templates/flannel/network-environment.j2
 rename roles/network_plugin/templates/{calico => }/network-environment.j2 (66%)

diff --git a/roles/network_plugin/tasks/flannel.yml b/roles/network_plugin/tasks/flannel.yml
index fc06c55ce..a43be9e40 100644
--- a/roles/network_plugin/tasks/flannel.yml
+++ b/roles/network_plugin/tasks/flannel.yml
@@ -44,10 +44,6 @@
   run_once: true
   delegate_to: "{{ groups['kube-master'][0] }}"
 
-- name: Write network-environment
-  template: src=flannel/network-environment.j2 dest=/etc/network-environment mode=u+x
-  notify: restart flannel
-
 - name: Launch Flannel
   service: name=flannel state=started enabled=yes
   notify:
diff --git a/roles/network_plugin/tasks/main.yml b/roles/network_plugin/tasks/main.yml
index 4b6c8c66a..e3ebf305f 100644
--- a/roles/network_plugin/tasks/main.yml
+++ b/roles/network_plugin/tasks/main.yml
@@ -4,13 +4,12 @@
   when: ( kube_network_plugin is defined and kube_network_plugin == "calico" and kube_network_plugin == "flannel" ) or
         kube_network_plugin is not defined 
 
+- name: Write network-environment
+  template: src=network-environment.j2 dest=/etc/network-environment mode=u+x
+
 - include: flannel.yml
   when: kube_network_plugin == "flannel"
 
-- name: Calico | Write network-environment
-  template: src=calico/network-environment.j2 dest=/etc/network-environment mode=u+x
-  when: kube_network_plugin == "calico"
-
 - include: calico.yml
   when: kube_network_plugin == "calico"
 
diff --git a/roles/network_plugin/templates/flannel/network-environment.j2 b/roles/network_plugin/templates/flannel/network-environment.j2
deleted file mode 100644
index ac0b171d4..000000000
--- a/roles/network_plugin/templates/flannel/network-environment.j2
+++ /dev/null
@@ -1 +0,0 @@
-FLANNEL_ETCD_PREFIX="--etcd-prefix=/{{ cluster_name }}/network"
diff --git a/roles/network_plugin/templates/calico/network-environment.j2 b/roles/network_plugin/templates/network-environment.j2
similarity index 66%
rename from roles/network_plugin/templates/calico/network-environment.j2
rename to roles/network_plugin/templates/network-environment.j2
index 2407f1ecb..2b89eb7e8 100755
--- a/roles/network_plugin/templates/calico/network-environment.j2
+++ b/roles/network_plugin/templates/network-environment.j2
@@ -1,19 +1,23 @@
-#! /usr/bin/bash
-# This node's IPv4 address
-CALICO_IPAM=true
-DEFAULT_IPV4={{ip | default(ansible_default_ipv4.address) }}
-
-{% if inventory_hostname in groups['kube-node'] %}
-# The kubernetes master IP
-KUBERNETES_MASTER={{ groups['kube-master'][0] }}
-
-# Location of etcd cluster used by Calico.  By default, this uses the etcd
-# instance running on the Kubernetes Master
-ETCD_AUTHORITY={{ groups['kube-master'][0] }}:4001
-
-# The kubernetes-apiserver location - used by the calico plugin
-KUBE_API_ROOT=http://{{ groups['kube-master'][0] }}:{{kube_master_insecure_port}}/api/v1/
-
-# Location of the calicoctl binary - used by the calico plugin
-CALICOCTL_PATH="{{ bin_dir }}/calicoctl"
-{% endif %}
+#! /usr/bin/bash
+{% if kube_network_plugin == "calico" %}
+# This node's IPv4 address
+CALICO_IPAM=true
+DEFAULT_IPV4={{ip | default(ansible_default_ipv4.address) }}
+
+{% if inventory_hostname in groups['kube-node'] %}
+# The kubernetes master IP
+KUBERNETES_MASTER={{ groups['kube-master'][0] }}
+
+# Location of etcd cluster used by Calico.  By default, this uses the etcd
+# instance running on the Kubernetes Master
+ETCD_AUTHORITY={{ groups['kube-master'][0] }}:2379
+
+# The kubernetes-apiserver location - used by the calico plugin
+KUBE_API_ROOT=http://{{ groups['kube-master'][0] }}:{{kube_apiserver_insecure_port}}/api/v1/
+
+# Location of the calicoctl binary - used by the calico plugin
+CALICOCTL_PATH="{{ bin_dir }}/calicoctl"
+{% endif %}
+{% else %}
+FLANNEL_ETCD_PREFIX="--etcd-prefix=/{{ cluster_name }}/network"
+{% endif %}
-- 
GitLab