From 517491a93aa1bf81ba3ef4b3a3849906ad80e502 Mon Sep 17 00:00:00 2001 From: caoyuan Date: Sun, 22 Jan 2017 22:28:19 +0800 Subject: [PATCH] Optimize reconfiguration for octavia Co-Authored-By: Mauricio Lima Change-Id: If6a0d935df9f8b84d7628b2c8753aa12627e2c8a Partially-implements: blueprint better-reconfigure --- ansible/roles/octavia/defaults/main.yml | 39 +++++++++ ansible/roles/octavia/handlers/main.yml | 85 +++++++++++++++++++ .../roles/octavia/tasks/bootstrap_service.yml | 11 ++- ansible/roles/octavia/tasks/config.yml | 69 ++++++++++----- ansible/roles/octavia/tasks/deploy.yml | 7 +- ansible/roles/octavia/tasks/pull.yml | 30 ++----- ansible/roles/octavia/tasks/reconfigure.yml | 76 +---------------- ansible/roles/octavia/tasks/start.yml | 48 ----------- ansible/roles/octavia/tasks/upgrade.yml | 3 +- 9 files changed, 188 insertions(+), 180 deletions(-) create mode 100644 ansible/roles/octavia/handlers/main.yml delete mode 100644 ansible/roles/octavia/tasks/start.yml diff --git a/ansible/roles/octavia/defaults/main.yml b/ansible/roles/octavia/defaults/main.yml index 0460fa7add..f3c9814be0 100644 --- a/ansible/roles/octavia/defaults/main.yml +++ b/ansible/roles/octavia/defaults/main.yml @@ -1,6 +1,45 @@ --- project_name: "octavia" +octavia_services: + octavia-api: + container_name: octavia_api + group: octavia-api + enabled: true + image: "{{ octavia_api_image_full }}" + volumes: + - "{{ node_config_directory }}/octavia-api/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + octavia-health-manager: + container_name: octavia_health_manager + group: octavia-health-manager + enabled: true + image: "{{ octavia_health_manager_image_full }}" + volumes: + - "{{ node_config_directory }}/octavia-health-manager/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + octavia-housekeeping: + container_name: octavia_housekeeping + group: octavia-housekeeping + enabled: true + image: "{{ octavia_housekeeping_image_full }}" + volumes: + - "{{ node_config_directory }}/octavia-housekeeping/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + octavia-worker: + container_name: octavia_worker + group: octavia-worker + enabled: true + image: "{{ octavia_worker_image_full }}" + volumes: + - "{{ node_config_directory }}/octavia-worker/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + + #################### # Database #################### diff --git a/ansible/roles/octavia/handlers/main.yml b/ansible/roles/octavia/handlers/main.yml new file mode 100644 index 0000000000..8740b990fe --- /dev/null +++ b/ansible/roles/octavia/handlers/main.yml @@ -0,0 +1,85 @@ +--- +- name: Restart octavia-api container + vars: + service_name: "octavia-api" + service: "{{ octavia_services[service_name] }}" + config_json: "{{ octavia_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + octavia_conf: "{{ octavia_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + octavia_api_container: "{{ check_octavia_containers.results|selectattr('item.key', 'equalto', service_name)|first }}" + kolla_docker: + action: "recreate_or_restart_container" + common_options: "{{ docker_common_options }}" + name: "{{ service.container_name }}" + image: "{{ service.image }}" + volumes: "{{ service.volumes }}" + when: + - action != "config" + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or octavia_conf.changed | bool + or octavia_api_container.changed | bool + +- name: Restart octavia-health-manager container + vars: + service_name: "octavia-health-manager" + service: "{{ octavia_services[service_name] }}" + config_json: "{{ octavia_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + octavia_conf: "{{ octavia_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + octavia_health_manager_container: "{{ check_octavia_containers.results|selectattr('item.key', 'equalto', service_name)|first }}" + kolla_docker: + action: "recreate_or_restart_container" + common_options: "{{ docker_common_options }}" + name: "{{ service.container_name }}" + image: "{{ service.image }}" + volumes: "{{ service.volumes }}" + when: + - action != "config" + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or octavia_conf.changed | bool + or octavia_health_manager_container.changed | bool + +- name: Restart octavia-housekeeping container + vars: + service_name: "octavia-housekeeping" + service: "{{ octavia_services[service_name] }}" + config_json: "{{ octavia_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + octavia_conf: "{{ octavia_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + octavia_housekeeping_container: "{{ check_octavia_containers.results|selectattr('item.key', 'equalto', service_name)|first }}" + kolla_docker: + action: "recreate_or_restart_container" + common_options: "{{ docker_common_options }}" + name: "{{ service.container_name }}" + image: "{{ service.image }}" + volumes: "{{ service.volumes }}" + when: + - action != "config" + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or octavia_conf.changed | bool + or octavia_housekeeping_container.changed | bool + +- name: Restart octavia-worker container + vars: + service_name: "octavia-worker" + service: "{{ octavia_services[service_name] }}" + config_json: "{{ octavia_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + octavia_conf: "{{ octavia_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + octavia_worker_container: "{{ check_octavia_containers.results|selectattr('item.key', 'equalto', service_name)|first }}" + kolla_docker: + action: "recreate_or_restart_container" + common_options: "{{ docker_common_options }}" + name: "{{ service.container_name }}" + image: "{{ service.image }}" + volumes: "{{ service.volumes }}" + when: + - action != "config" + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or octavia_conf.changed | bool + or octavia_worker_certificate.changed | bool + or octavia_worker_container.changed | bool diff --git a/ansible/roles/octavia/tasks/bootstrap_service.yml b/ansible/roles/octavia/tasks/bootstrap_service.yml index ba5fa7f185..0580808c0d 100644 --- a/ansible/roles/octavia/tasks/bootstrap_service.yml +++ b/ansible/roles/octavia/tasks/bootstrap_service.yml @@ -1,5 +1,7 @@ --- - name: Running Octavia bootstrap container + vars: + octavia_api: "{{ octavia_services['octavia-api'] }}" kolla_docker: action: "start_container" common_options: "{{ docker_common_options }}" @@ -7,14 +9,11 @@ environment: KOLLA_BOOTSTRAP: KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - image: "{{ octavia_api_image_full }}" + image: "{{ octavia_api.image }}" labels: BOOTSTRAP: name: "bootstrap_octavia" restart_policy: "never" - volumes: - - "{{ node_config_directory }}/octavia-api/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" + volumes: "{{ octavia_api.volumes }}" run_once: True - delegate_to: "{{ groups['octavia-api'][0] }}" + delegate_to: "{{ groups[octavia_api.group][0] }}" diff --git a/ansible/roles/octavia/tasks/config.yml b/ansible/roles/octavia/tasks/config.yml index 23658a8aaa..0f76250b00 100644 --- a/ansible/roles/octavia/tasks/config.yml +++ b/ansible/roles/octavia/tasks/config.yml @@ -1,49 +1,76 @@ --- - name: Ensuring config directories exist file: - path: "{{ node_config_directory }}/{{ item }}" + path: "{{ node_config_directory }}/{{ item.key }}" state: "directory" recurse: yes - with_items: - - "octavia-api" - - "octavia-health-manager" - - "octavia-housekeeping" - - "octavia-worker" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ octavia_services }}" - name: Copying over config.json files for services template: - src: "{{ item }}.json.j2" - dest: "{{ node_config_directory }}/{{ item }}/config.json" - with_items: - - "octavia-api" - - "octavia-health-manager" - - "octavia-housekeeping" - - "octavia-worker" + src: "{{ item.key }}.json.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/config.json" + register: octavia_config_jsons + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ octavia_services }}" + notify: + - "Restart {{ item.key }} container" - name: Copying over octavia.conf merge_configs: vars: - service_name: "{{ item }}" + service_name: "{{ item.key }}" sources: - "{{ role_path }}/templates/octavia.conf.j2" - "{{ node_config_directory }}/config/global.conf" - "{{ node_config_directory }}/config/database.conf" - "{{ node_config_directory }}/config/messaging.conf" - "{{ node_config_directory }}/config/octavia.conf" - - "{{ node_config_directory }}/config/octavia/{{ item }}.conf" + - "{{ node_config_directory }}/config/octavia/{{ item.key }}.conf" - "{{ node_config_directory }}/config/octavia/{{ inventory_hostname }}/octavia.conf" - dest: "{{ node_config_directory }}/{{ item }}/octavia.conf" - with_items: - - "octavia-api" - - "octavia-health-manager" - - "octavia-housekeeping" - - "octavia-worker" + dest: "{{ node_config_directory }}/{{ item.key }}/octavia.conf" + register: octavia_confs + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ octavia_services }}" + notify: + - "Restart {{ item.key }} container" - name: Copying certificate files + vars: + service: "{{ octavia_services['octavia-worker'] }}" copy: src: "{{ node_config_directory }}/config/octavia/{{ item }}" dest: "{{ node_config_directory }}/octavia-worker/{{ item }}" + register: octavia_worker_certificate + when: + - inventory_hostname in groups[service.group] + - service.enabled | bool with_items: - cakey.pem - ca_01.pem - client.pem + notify: + - Restart octavia-worker container + +- name: Check octavia containers + kolla_docker: + action: "compare_container" + common_options: "{{ docker_common_options }}" + name: "{{ item.value.container_name }}" + image: "{{ item.value.image }}" + volumes: "{{ item.value.volumes }}" + register: check_octavia_containers + when: + - action != "config" + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ octavia_services }}" + notify: + - "Restart {{ item.key }} container" diff --git a/ansible/roles/octavia/tasks/deploy.yml b/ansible/roles/octavia/tasks/deploy.yml index c75a5e6026..d289034be5 100644 --- a/ansible/roles/octavia/tasks/deploy.yml +++ b/ansible/roles/octavia/tasks/deploy.yml @@ -11,8 +11,5 @@ - include: "bootstrap.yml" when: inventory_hostname in groups['octavia-api'] -- include: "start.yml" - when: inventory_hostname in groups['octavia-api'] or - inventory_hostname in groups['octavia-health-manager'] or - inventory_hostname in groups['octavia-housekeeping'] or - inventory_hostname in groups['octavia-worker'] +- name: Flush handlers + meta: flush_handlers diff --git a/ansible/roles/octavia/tasks/pull.yml b/ansible/roles/octavia/tasks/pull.yml index 2b51b139da..8c03466ca6 100644 --- a/ansible/roles/octavia/tasks/pull.yml +++ b/ansible/roles/octavia/tasks/pull.yml @@ -1,28 +1,10 @@ --- -- name: Pulling octavia-api image +- name: Pulling octavia images kolla_docker: action: "pull_image" common_options: "{{ docker_common_options }}" - image: "{{ octavia_api_image_full }}" - when: inventory_hostname in groups['octavia-api'] - -- name: Pulling octavia-health-manager image - kolla_docker: - action: "pull_image" - common_options: "{{ docker_common_options }}" - image: "{{ octavia_health_manager_image_full }}" - when: inventory_hostname in groups['octavia-health-manager'] - -- name: Pulling octavia-housekeeping image - kolla_docker: - action: "pull_image" - common_options: "{{ docker_common_options }}" - image: "{{ octavia_housekeeping_image_full }}" - when: inventory_hostname in groups['octavia-housekeeping'] - -- name: Pulling octavia-worker image - kolla_docker: - action: "pull_image" - common_options: "{{ docker_common_options }}" - image: "{{ octavia_worker_image_full }}" - when: inventory_hostname in groups['octavia-worker'] + image: "{{ item.value.image }}" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ octavia_services }}" diff --git a/ansible/roles/octavia/tasks/reconfigure.yml b/ansible/roles/octavia/tasks/reconfigure.yml index c9f85a8838..e078ef1318 100644 --- a/ansible/roles/octavia/tasks/reconfigure.yml +++ b/ansible/roles/octavia/tasks/reconfigure.yml @@ -1,76 +1,2 @@ --- -- name: Ensuring the containers up - kolla_docker: - name: "{{ item.name }}" - action: "get_container_state" - register: container_state - failed_when: container_state.Running == false - when: inventory_hostname in groups[item.group] - with_items: - - { name: octavia_api, group: octavia-api } - - { name: octavia_health_manager, group: octavia-health-manager } - - { name: octavia_housekeeping, group: octavia-housekeeping } - - { name: octavia_worker, group: octavia-worker } - -- include: config.yml - -- name: Check the configs - command: docker exec {{ item.name }} /usr/local/bin/kolla_set_configs --check - changed_when: false - failed_when: false - register: check_results - when: inventory_hostname in groups[item.group] - with_items: - - { name: octavia_api, group: octavia-api } - - { name: octavia_health_manager, group: octavia-health-manager } - - { name: octavia_housekeeping, group: octavia-housekeeping } - - { name: octavia_worker, group: octavia-worker } - -- name: Containers config strategy - kolla_docker: - name: "{{ item.name }}" - action: "get_container_env" - register: container_envs - when: inventory_hostname in groups[item.group] - with_items: - - { name: octavia_api, group: octavia-api } - - { name: octavia_health_manager, group: octavia-health-manager } - - { name: octavia_housekeeping, group: octavia-housekeeping } - - { name: octavia_worker, group: octavia-worker } - -- name: Remove the containers - kolla_docker: - name: "{{ item[0]['name'] }}" - action: "remove_container" - register: remove_containers - when: - - inventory_hostname in groups[item[0]['group']] - - config_strategy == "COPY_ONCE" or item[1]['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE' - - item[2]['rc'] == 1 - with_together: - - [{ name: octavia_api, group: octavia-api }, - { name: octavia_health_manager, group: octavia-health-manager }, - { name: octavia_housekeeping, group: octavia-housekeeping }, - { name: octavia_worker, group: octavia-worker }] - - "{{ container_envs.results }}" - - "{{ check_results.results }}" - -- include: start.yml - when: remove_containers.changed - -- name: Restart containers - kolla_docker: - name: "{{ item[0]['name'] }}" - action: "restart_container" - when: - - inventory_hostname in groups[item[0]['group']] - - config_strategy == 'COPY_ALWAYS' - - item[1]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE' - - item[2]['rc'] == 1 - with_together: - - [{ name: octavia_api, group: octavia-api }, - { name: octavia_health_manager, group: octavia-health-manager }, - { name: octavia_housekeeping, group: octavia-housekeeping }, - { name: octavia_worker, group: octavia-worker }] - - "{{ container_envs.results }}" - - "{{ check_results.results }}" +- include: deploy.yml diff --git a/ansible/roles/octavia/tasks/start.yml b/ansible/roles/octavia/tasks/start.yml deleted file mode 100644 index cf7d23bb12..0000000000 --- a/ansible/roles/octavia/tasks/start.yml +++ /dev/null @@ -1,48 +0,0 @@ ---- -- name: Starting octavia-api container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ octavia_api_image_full }}" - name: "octavia_api" - volumes: - - "{{ node_config_directory }}/octavia-api/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - when: inventory_hostname in groups['octavia-api'] - -- name: Starting octavia-health-manager container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ octavia_health_manager_image_full }}" - name: "octavia_health_manager" - volumes: - - "{{ node_config_directory }}/octavia-health-manager/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - when: inventory_hostname in groups['octavia-health-manager'] - -- name: Starting octavia-housekeeping container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ octavia_housekeeping_image_full }}" - name: "octavia_housekeeping" - volumes: - - "{{ node_config_directory }}/octavia-housekeeping/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - when: inventory_hostname in groups['octavia-housekeeping'] - -- name: Starting octavia-worker container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ octavia_worker_image_full }}" - name: "octavia_worker" - volumes: - - "{{ node_config_directory }}/octavia-worker/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - when: inventory_hostname in groups['octavia-worker'] diff --git a/ansible/roles/octavia/tasks/upgrade.yml b/ansible/roles/octavia/tasks/upgrade.yml index 77ffb53e90..ab84a3dda9 100644 --- a/ansible/roles/octavia/tasks/upgrade.yml +++ b/ansible/roles/octavia/tasks/upgrade.yml @@ -3,4 +3,5 @@ - include: "bootstrap_service.yml" -- include: "start.yml" +- name: Flush handlers + meta: flush_handlers