From 3958a68fb1823671f30f9334f0714b326ce1f756 Mon Sep 17 00:00:00 2001
From: Eduardo Gonzalez <dabarren@gmail.com>
Date: Tue, 13 Jun 2017 16:24:08 +0200
Subject: [PATCH] Deploy etcd in compute nodes when kuryr

Kuryr need etcd on each compute node to store
network data.
Etcd is only deployed in controller nodes at this moment.

Also this change remove and useless bootstrap tasks.

Depends-On: I9c6c876773288c2f951966498db0ff8af090ac20
Change-Id: I8a84334e831fb15f6cbdd3bc34d2159638df6b85
Closes-Bug: #1697699
---
 ansible/inventory/all-in-one           |  1 +
 ansible/inventory/multinode            |  1 +
 ansible/roles/etcd/defaults/main.yml   |  5 +++++
 ansible/roles/etcd/handlers/main.yml   |  2 +-
 ansible/roles/etcd/tasks/bootstrap.yml | 19 -------------------
 ansible/roles/etcd/tasks/config.yml    |  6 +++---
 ansible/roles/etcd/tasks/deploy.yml    |  2 --
 ansible/roles/etcd/tasks/pull.yml      |  2 +-
 8 files changed, 12 insertions(+), 26 deletions(-)
 delete mode 100644 ansible/roles/etcd/tasks/bootstrap.yml

diff --git a/ansible/inventory/all-in-one b/ansible/inventory/all-in-one
index 6c089fbcd..4eb713e99 100644
--- a/ansible/inventory/all-in-one
+++ b/ansible/inventory/all-in-one
@@ -40,6 +40,7 @@ monitoring
 
 [etcd:children]
 control
+compute
 
 [karbor:children]
 control
diff --git a/ansible/inventory/multinode b/ansible/inventory/multinode
index c21426d50..89b0ac828 100644
--- a/ansible/inventory/multinode
+++ b/ansible/inventory/multinode
@@ -58,6 +58,7 @@ monitoring
 
 [etcd:children]
 control
+compute
 
 [influxdb:children]
 monitoring
diff --git a/ansible/roles/etcd/defaults/main.yml b/ansible/roles/etcd/defaults/main.yml
index 44c51bbcd..b1ebfaf08 100644
--- a/ansible/roles/etcd/defaults/main.yml
+++ b/ansible/roles/etcd/defaults/main.yml
@@ -19,6 +19,11 @@ etcd_services:
       ETCD_OUT_FILE: "/var/log/kolla/etcd/etcd.log"
       KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
     image: "{{ etcd_image_full }}"
+    host_in_groups: >-
+      {{
+      inventory_hostname in groups['control']
+      or (enable_kuryr | bool and inventory_hostname in groups['compute'])
+      }}
     volumes:
       - "{{ node_config_directory }}/etcd/:{{ container_config_directory }}/:ro"
       - "/etc/localtime:/etc/localtime:ro"
diff --git a/ansible/roles/etcd/handlers/main.yml b/ansible/roles/etcd/handlers/main.yml
index 0b09a33cd..1410478c8 100644
--- a/ansible/roles/etcd/handlers/main.yml
+++ b/ansible/roles/etcd/handlers/main.yml
@@ -14,7 +14,7 @@
     volumes: "{{ service.volumes }}"
   when:
     - action != "config"
-    - inventory_hostname in groups[service.group]
     - service.enabled | bool
+    - service.host_in_groups | bool
     - config_json.changed | bool
       or etcd_container.changed | bool
diff --git a/ansible/roles/etcd/tasks/bootstrap.yml b/ansible/roles/etcd/tasks/bootstrap.yml
deleted file mode 100644
index 86fc77ffa..000000000
--- a/ansible/roles/etcd/tasks/bootstrap.yml
+++ /dev/null
@@ -1,19 +0,0 @@
----
-- name: Running etcd bootstrap container
-  vars:
-    etcd: "{{ etcd_services['etcd'] }}"
-  kolla_docker:
-    action: "start_container"
-    common_options: "{{ docker_common_options }}"
-    detach: False
-    environment:
-      KOLLA_BOOTSTRAP:
-      KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
-    image: "{{ etcd.image }}"
-    labels:
-      BOOTSTRAP:
-    name: "bootstrap_etcd"
-    restart_policy: "never"
-    volumes: "{{ etcd.volumes }}"
-  run_once: True
-  delegate_to: "{{ groups[etcd.group][0] }}"
diff --git a/ansible/roles/etcd/tasks/config.yml b/ansible/roles/etcd/tasks/config.yml
index 9d2e43b6d..dba8fef69 100644
--- a/ansible/roles/etcd/tasks/config.yml
+++ b/ansible/roles/etcd/tasks/config.yml
@@ -5,8 +5,8 @@
     state: "directory"
     recurse: yes
   when:
-    - inventory_hostname in groups[item.value.group]
     - item.value.enabled | bool
+    - item.value.host_in_groups | bool
   with_dict: "{{ etcd_services }}"
 
 - name: Copying over config.json files for services
@@ -15,8 +15,8 @@
     dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
   register: etcd_config_jsons
   when:
-    - inventory_hostname in groups[item.value.group]
     - item.value.enabled | bool
+    - item.value.host_in_groups | bool
   with_dict: "{{ etcd_services }}"
   notify:
     - Restart etcd container
@@ -31,8 +31,8 @@
   register: check_etcd_containers
   when:
     - action != "config"
-    - inventory_hostname in groups[item.value.group]
     - item.value.enabled | bool
+    - item.value.host_in_groups | bool
   with_dict: "{{ etcd_services }}"
   notify:
     - Restart etcd container
diff --git a/ansible/roles/etcd/tasks/deploy.yml b/ansible/roles/etcd/tasks/deploy.yml
index 9eca42dec..dd26ecc34 100644
--- a/ansible/roles/etcd/tasks/deploy.yml
+++ b/ansible/roles/etcd/tasks/deploy.yml
@@ -1,7 +1,5 @@
 ---
 - include: config.yml
 
-- include: bootstrap.yml
-
 - name: Flush handlers
   meta: flush_handlers
diff --git a/ansible/roles/etcd/tasks/pull.yml b/ansible/roles/etcd/tasks/pull.yml
index 8fa205c68..c88e003aa 100644
--- a/ansible/roles/etcd/tasks/pull.yml
+++ b/ansible/roles/etcd/tasks/pull.yml
@@ -5,6 +5,6 @@
     common_options: "{{ docker_common_options }}"
     image: "{{ item.value.image }}"
   when:
-    - inventory_hostname in groups[item.value.group]
     - item.value.enabled | bool
+    - item.value.host_in_groups | bool
   with_dict: "{{ etcd_services }}"
-- 
GitLab