From cc149dd0c65f322606bef8ee392fc591cc698289 Mon Sep 17 00:00:00 2001 From: Eduardo Gonzalez Date: Wed, 18 Jan 2017 14:51:17 +0000 Subject: [PATCH] Optimize reconfiguration for tacker Change-Id: I5258b6e1384d75972b64a2b83d1913545b5af44d Partically-implements: blueprint better-reconfigure --- ansible/roles/tacker/defaults/main.yml | 11 ++++ ansible/roles/tacker/handlers/main.yml | 23 +++++++ .../roles/tacker/tasks/bootstrap_service.yml | 11 ++-- ansible/roles/tacker/tasks/config.yml | 63 +++++++++++++----- ansible/roles/tacker/tasks/deploy.yml | 3 +- ansible/roles/tacker/tasks/pull.yml | 6 +- ansible/roles/tacker/tasks/reconfigure.yml | 64 +------------------ ansible/roles/tacker/tasks/start.yml | 11 ---- ansible/roles/tacker/tasks/upgrade.yml | 3 +- 9 files changed, 96 insertions(+), 99 deletions(-) create mode 100644 ansible/roles/tacker/handlers/main.yml delete mode 100644 ansible/roles/tacker/tasks/start.yml diff --git a/ansible/roles/tacker/defaults/main.yml b/ansible/roles/tacker/defaults/main.yml index 6c1fc6c0e3..8a3eb9909c 100644 --- a/ansible/roles/tacker/defaults/main.yml +++ b/ansible/roles/tacker/defaults/main.yml @@ -1,6 +1,17 @@ --- project_name: "tacker" +tacker_services: + tacker: + container_name: "tacker" + group: "tacker" + enabled: true + image: "{{ tacker_image_full }}" + volumes: + - "{{ node_config_directory }}/tacker/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + #################### # Database #################### diff --git a/ansible/roles/tacker/handlers/main.yml b/ansible/roles/tacker/handlers/main.yml new file mode 100644 index 0000000000..718e26a4de --- /dev/null +++ b/ansible/roles/tacker/handlers/main.yml @@ -0,0 +1,23 @@ +--- +- name: Restart tacker container + vars: + service_name: "tacker" + service: "{{ tacker_services[service_name] }}" + config_json: "{{ tacker_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + tacker_conf: "{{ tacker_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + policy_json: "{{ tacker_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + tacker_container: "{{ check_tacker_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|reject('equalto', '')|list }}" + when: + - action != "config" + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or tacker_conf.changed | bool + or policy_json.changed | bool + or tacker_container.changed | bool diff --git a/ansible/roles/tacker/tasks/bootstrap_service.yml b/ansible/roles/tacker/tasks/bootstrap_service.yml index 039f3e6d99..b81e2fccf1 100644 --- a/ansible/roles/tacker/tasks/bootstrap_service.yml +++ b/ansible/roles/tacker/tasks/bootstrap_service.yml @@ -1,5 +1,7 @@ --- - name: Running tacker bootstrap container + vars: + tacker: "{{ tacker_services.tacker }}" kolla_docker: action: "start_container" common_options: "{{ docker_common_options }}" @@ -7,14 +9,11 @@ environment: KOLLA_BOOTSTRAP: KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - image: "{{ tacker_image_full }}" + image: "{{ tacker.image }}" labels: BOOTSTRAP: name: "bootstrap_tacker" restart_policy: "never" - volumes: - - "{{ node_config_directory }}/tacker/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" + volumes: "{{ tacker.volumes|reject('equalto', '')|list }}" run_once: True - delegate_to: "{{ groups['tacker'][0] }}" + delegate_to: "{{ groups[tacker.group][0] }}" diff --git a/ansible/roles/tacker/tasks/config.yml b/ansible/roles/tacker/tasks/config.yml index b7d821d0dd..478b41844b 100644 --- a/ansible/roles/tacker/tasks/config.yml +++ b/ansible/roles/tacker/tasks/config.yml @@ -1,34 +1,46 @@ --- - name: Ensuring config directories exist file: - path: "{{ node_config_directory }}/{{ item }}" + path: "{{ node_config_directory }}/{{ item.key }}" state: "directory" recurse: yes - with_items: - - "tacker" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled + with_dict: "{{ tacker_services }}" - name: Copying over config.json files for services template: - src: "{{ item }}.json.j2" - dest: "{{ node_config_directory }}/{{ item }}/config.json" - with_items: - - "tacker" + src: "{{ item.key }}.json.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/config.json" + register: tacker_config_jsons + with_dict: "{{ tacker_services }}" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled + notify: + - Restart tacker container - name: Copying over tacker.conf merge_configs: vars: - service_name: "{{ item }}" + service_name: "{{ item.key }}" sources: - "{{ role_path }}/templates/tacker.conf.j2" - "{{ node_custom_config }}/global.conf" - "{{ node_custom_config }}/database.conf" - "{{ node_custom_config }}/messaging.conf" - "{{ node_custom_config }}/tacker.conf" - - "{{ node_custom_config }}/tacker/{{ item }}.conf" + - "{{ node_custom_config }}/tacker/{{ item.key }}.conf" - "{{ node_custom_config }}/tacker/{{ inventory_hostname }}/tacker.conf" - dest: "{{ node_config_directory }}/{{ item }}/tacker.conf" - with_items: - - "tacker" + dest: "{{ node_config_directory }}/{{ item.key }}/tacker.conf" + register: tacker_confs + with_dict: "{{ tacker_services }}" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + notify: + - Restart tacker container - name: Check if policies shall be overwritten local_action: stat path="{{ node_custom_config }}/tacker/policy.json" @@ -37,8 +49,27 @@ - name: Copying over existing policy.json template: src: "{{ node_custom_config }}/tacker/policy.json" - dest: "{{ node_config_directory }}/{{ item }}/policy.json" - with_items: - - "tacker" + dest: "{{ node_config_directory }}/{{ item.key }}/policy.json" + register: tacker_policy_jsons when: - tacker_policy.stat.exists + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + - tacker_policy.stat.exists + with_dict: "{{ tacker_services }}" + notify: + - Restart tacker containers + +- name: Check tacker containers + kolla_docker: + action: "compare_container" + name: "{{ item.value.container_name }}" + image: "{{ item.value.image }}" + volumes: "{{ item.value.volumes|reject('equalto', '')|list }}" + when: + - action != 'config' + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + register: check_tacker_containers + with_dict: "{{ tacker_services }}" + notify: + - Restart tacker container diff --git a/ansible/roles/tacker/tasks/deploy.yml b/ansible/roles/tacker/tasks/deploy.yml index 5c48120b7c..864362ba5f 100644 --- a/ansible/roles/tacker/tasks/deploy.yml +++ b/ansible/roles/tacker/tasks/deploy.yml @@ -5,4 +5,5 @@ - include: bootstrap.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers diff --git a/ansible/roles/tacker/tasks/pull.yml b/ansible/roles/tacker/tasks/pull.yml index c1e1bd19af..c2062c774e 100644 --- a/ansible/roles/tacker/tasks/pull.yml +++ b/ansible/roles/tacker/tasks/pull.yml @@ -3,4 +3,8 @@ kolla_docker: action: "pull_image" common_options: "{{ docker_common_options }}" - image: "{{ tacker_image_full }}" + image: "{{ item.value.image }}" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ tacker_services }}" diff --git a/ansible/roles/tacker/tasks/reconfigure.yml b/ansible/roles/tacker/tasks/reconfigure.yml index 60a29c0f06..e078ef1318 100644 --- a/ansible/roles/tacker/tasks/reconfigure.yml +++ b/ansible/roles/tacker/tasks/reconfigure.yml @@ -1,64 +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: tacker, group: tacker } - -- 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: tacker, group: tacker } - -# NOTE(jeffrey4l): when config_strategy == 'COPY_ALWAYS' -# and container env['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE', -# just remove the container and start again -- 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: tacker, group: tacker } - -- name: Remove the containers - kolla_docker: - name: "{{ item[0]['name'] }}" - action: "remove_container" - register: remove_containers - when: - - config_strategy == "COPY_ONCE" or item[1]['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE' - - item[2]['rc'] == 1 - - inventory_hostname in groups[item[0]['group']] - with_together: - - [{ name: tacker, group: tacker }] - - "{{ 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: - - config_strategy == 'COPY_ALWAYS' - - item[1]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE' - - item[2]['rc'] == 1 - - inventory_hostname in groups[item[0]['group']] - with_together: - - [{ name: tacker, group: tacker }] - - "{{ container_envs.results }}" - - "{{ check_results.results }}" +- include: deploy.yml diff --git a/ansible/roles/tacker/tasks/start.yml b/ansible/roles/tacker/tasks/start.yml deleted file mode 100644 index 2d8214fe7b..0000000000 --- a/ansible/roles/tacker/tasks/start.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Starting tacker container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ tacker_image_full }}" - name: "tacker" - volumes: - - "{{ node_config_directory }}/tacker/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" diff --git a/ansible/roles/tacker/tasks/upgrade.yml b/ansible/roles/tacker/tasks/upgrade.yml index 308053080c..c38db1adf4 100644 --- a/ansible/roles/tacker/tasks/upgrade.yml +++ b/ansible/roles/tacker/tasks/upgrade.yml @@ -3,4 +3,5 @@ - include: bootstrap_service.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers