diff --git a/ansible/library/kolla_container_facts.py b/ansible/library/kolla_container_facts.py new file mode 100644 index 0000000000..a2c73009d7 --- /dev/null +++ b/ansible/library/kolla_container_facts.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python + +# Copyright 2016 99cloud +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +DOCUMENTATION = ''' +--- +module: kolla_container_facts +short_description: Module for collecting Docker container facts +description: + - A module targeting at collecting Docker container facts. It is used for + detecting whether the container is running on host in Kolla. +options: + api_version: + description: + - The version of the api for docker-py to use when contacting docker + required: False + type: str + default: auto + name: + description: + - Name or names of the containers + required: False + type: str or list +author: Jeffrey Zhang +''' + +EXAMPLES = ''' +- hosts: all + tasks: + - name: Gather docker facts + kolla_container_facts: + + - name: Gather glance container facts + kolla_container_facts: + name: + - glance_api + - glance_registry +''' + +import docker + + +def main(): + argument_spec = dict( + name=dict(required=False, type='list', default=[]), + api_version=dict(required=False, type='str', default='auto') + ) + + module = AnsibleModule(argument_spec=argument_spec) + + results = dict(changed=False, _containers=[]) + client = docker.Client(version=module.params.get('api_version')) + containers = client.containers() + names = module.params.get('name') + if names and not isinstance(names, list): + names = [names] + for container in containers: + for container_name in container['Names']: + # remove '/' prefix character + container_name = container_name[1:] + if names and container_name not in names: + continue + results['_containers'].append(container) + results[container_name] = container + module.exit_json(**results) + + +from ansible.module_utils.basic import * # noqa +if __name__ == "__main__": + main() diff --git a/ansible/roles/glance/tasks/precheck.yml b/ansible/roles/glance/tasks/precheck.yml index ed97d539c0..37876d4f41 100644 --- a/ansible/roles/glance/tasks/precheck.yml +++ b/ansible/roles/glance/tasks/precheck.yml @@ -1 +1,27 @@ --- +- name: Get container facts + kolla_container_facts: + name: + - glance_api + - glance_registry + register: container_facts + +- name: Checking free port for Glance API + wait_for: + host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}" + port: "{{ glance_api_port }}" + connect_timeout: 1 + state: stopped + when: + - inventory_hostname in groups['glance-api'] + - container_facts['glance_api'] is not defined + +- name: Checking free port for Glance Registry + wait_for: + host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}" + port: "{{ glance_registry_port }}" + connect_timeout: 1 + state: stopped + when: + - inventory_hostname in groups['glance-registry'] + - container_facts['glance_registry'] is not defined diff --git a/ansible/roles/haproxy/tasks/precheck.yml b/ansible/roles/haproxy/tasks/precheck.yml index ed97d539c0..0dc35c9802 100644 --- a/ansible/roles/haproxy/tasks/precheck.yml +++ b/ansible/roles/haproxy/tasks/precheck.yml @@ -1 +1,37 @@ --- +- name: Get container facts + kolla_container_facts: + name: haproxy + register: container_facts + +- name: Getting haproxy stat + shell: echo "show stat" | docker exec -i haproxy socat unix-connect:/var/lib/kolla/haproxy/haproxy.sock stdio + register: haproxy_stat_shell + changed_when: false + failed_when: false + when: container_facts['haproxy'] is defined + +- set_fact: + haproxy_stat: "{{ haproxy_stat_shell.stdout|default('') }}" + +- name: Checking free port for Glance API HAProxy + wait_for: + host: "{{ kolla_internal_vip_address }}" + port: "{{ glance_api_port }}" + connect_timeout: 1 + state: stopped + when: + - enable_glance | bool + - inventory_hostname in groups['haproxy'] + - "{{ 'glance_api' not in haproxy_stat }}" + +- name: Checking free port for Glance Registry HAProxy + wait_for: + host: "{{ kolla_internal_vip_address }}" + port: "{{ glance_registry_port }}" + connect_timeout: 1 + state: stopped + when: + - enable_glance | bool + - inventory_hostname in groups['haproxy'] + - "{{ 'glance_registry' not in haproxy_stat }}" diff --git a/ansible/roles/prechecks/tasks/port_checks.yml b/ansible/roles/prechecks/tasks/port_checks.yml index 7aa1e0d673..1968b6153c 100644 --- a/ansible/roles/prechecks/tasks/port_checks.yml +++ b/ansible/roles/prechecks/tasks/port_checks.yml @@ -173,46 +173,6 @@ - inventory_hostname in groups['etcd'] - enable_etcd | bool -- name: Checking free port for Glance API - wait_for: - host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}" - port: "{{ glance_api_port }}" - connect_timeout: 1 - state: stopped - when: - - inventory_hostname in groups['glance-api'] - - enable_glance | bool - -- name: Checking free port for Glance API HAProxy - wait_for: - host: "{{ kolla_internal_vip_address }}" - port: "{{ glance_api_port }}" - connect_timeout: 1 - state: stopped - when: - - inventory_hostname in groups['haproxy'] - - enable_glance | bool - -- name: Checking free port for Glance Registry - wait_for: - host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}" - port: "{{ glance_registry_port }}" - connect_timeout: 1 - state: stopped - when: - - inventory_hostname in groups['glance-registry'] - - enable_glance | bool - -- name: Checking free port for Glance Registry HAProxy - wait_for: - host: "{{ kolla_internal_vip_address }}" - port: "{{ glance_registry_port }}" - connect_timeout: 1 - state: stopped - when: - - inventory_hostname in groups['haproxy'] - - enable_glance | bool - - name: Checking free port for Gnocchi API wait_for: host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}"