From dba142e8b72f1459eeaf2ddd7e070f12e4a8e146 Mon Sep 17 00:00:00 2001
From: caoyuan <cao.yuan@99cloud.net>
Date: Thu, 22 Dec 2016 16:42:56 +0800
Subject: [PATCH] Move congress precheck into its own role

Change-Id: I775b039a07daf27460fa288ecb2886417513f411
Partially-implements: blueprint condition-pre-check
---
 ansible/roles/congress/tasks/precheck.yml     | 15 ++++++++++++++
 ansible/roles/haproxy/tasks/precheck.yml      | 11 ++++++++++
 ansible/roles/prechecks/tasks/port_checks.yml | 20 -------------------
 3 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/ansible/roles/congress/tasks/precheck.yml b/ansible/roles/congress/tasks/precheck.yml
index ed97d539c0..5092237a09 100644
--- a/ansible/roles/congress/tasks/precheck.yml
+++ b/ansible/roles/congress/tasks/precheck.yml
@@ -1 +1,16 @@
 ---
+- name: Get container facts
+  kolla_container_facts:
+    name:
+      - congress_api
+  register: container_facts
+
+- name: Checking free port for Congress API
+  wait_for:
+    host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}"
+    port: "{{ congress_api_port }}"
+    connect_timeout: 1
+    state: stopped
+  when:
+    - container_facts['congress_api'] is not defined
+    - inventory_hostname in groups['congress-api']
diff --git a/ansible/roles/haproxy/tasks/precheck.yml b/ansible/roles/haproxy/tasks/precheck.yml
index ffac091162..61850e9c98 100644
--- a/ansible/roles/haproxy/tasks/precheck.yml
+++ b/ansible/roles/haproxy/tasks/precheck.yml
@@ -69,6 +69,17 @@
     - "{{ 'cloudkitty_api' not in haproxy_stat }}"
     - inventory_hostname in groups['haproxy']
 
+- name: Checking free port for Congress API HAProxy
+  wait_for:
+    host: "{{ kolla_internal_vip_address }}"
+    port: "{{ congress_api_port }}"
+    connect_timeout: 1
+    state: stopped
+  when:
+    - enable_congress | bool
+    - "{{ 'congress_api' not in haproxy_stat }}"
+    - inventory_hostname in groups['haproxy']
+
 - name: Checking free port for Designate API HAProxy
   wait_for:
     host: "{{ kolla_internal_vip_address }}"
diff --git a/ansible/roles/prechecks/tasks/port_checks.yml b/ansible/roles/prechecks/tasks/port_checks.yml
index 3dd53cd016..7b2e0add53 100644
--- a/ansible/roles/prechecks/tasks/port_checks.yml
+++ b/ansible/roles/prechecks/tasks/port_checks.yml
@@ -33,26 +33,6 @@
                 kolla_internal_vip_address | ipaddr(ip_addr_output.stdout.split()[3]) is none"
   when: enable_haproxy | bool
 
-- name: Checking free port for Congress API
-  wait_for:
-    host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}"
-    port: "{{ congress_api_port }}"
-    connect_timeout: 1
-    state: stopped
-  when:
-    - enable_congress | bool
-    - inventory_hostname in groups['congress-api']
-
-- name: Checking free port for Congress API HAProxy
-  wait_for:
-    host: "{{ kolla_internal_vip_address }}"
-    port: "{{ congress_api_port }}"
-    connect_timeout: 1
-    state: stopped
-  when:
-    - enable_congress | bool
-    - inventory_hostname in groups['haproxy']
-
 - name: Checking free port for Etcd Peer
   wait_for:
     host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}"
-- 
GitLab