From 6e6327e822bfb7ba81c3b0ccefc36da89cd6f9fe Mon Sep 17 00:00:00 2001 From: Jeffrey Zhang Date: Mon, 19 Dec 2016 00:09:41 +0800 Subject: [PATCH] Optimize reconfigure action for memcached Change-Id: Ia127e29fd07bf01eb817e3d319d56f17854b09c9 Partically-implements: blueprint better-reconfigure --- ansible/roles/memcached/defaults/main.yml | 11 ++++ ansible/roles/memcached/handlers/main.yml | 14 ++++ ansible/roles/memcached/tasks/config.yml | 17 +++++ ansible/roles/memcached/tasks/deploy.yml | 2 - ansible/roles/memcached/tasks/pull.yml | 8 ++- ansible/roles/memcached/tasks/reconfigure.yml | 65 +------------------ ansible/roles/memcached/tasks/start.yml | 11 ---- ansible/roles/memcached/tasks/upgrade.yml | 2 - 8 files changed, 49 insertions(+), 81 deletions(-) create mode 100644 ansible/roles/memcached/handlers/main.yml mode change 100644 => 120000 ansible/roles/memcached/tasks/reconfigure.yml delete mode 100644 ansible/roles/memcached/tasks/start.yml diff --git a/ansible/roles/memcached/defaults/main.yml b/ansible/roles/memcached/defaults/main.yml index 8377b77d47..2e02b716d9 100644 --- a/ansible/roles/memcached/defaults/main.yml +++ b/ansible/roles/memcached/defaults/main.yml @@ -1,6 +1,17 @@ --- project_name: "memcached" +memcached_services: + memcached: + container_name: "memcached" + image: "{{ memcached_image_full }}" + enabled: true + group: "memcached" + volumes: + - "{{ node_config_directory }}/memcached/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + + #################### # Docker #################### diff --git a/ansible/roles/memcached/handlers/main.yml b/ansible/roles/memcached/handlers/main.yml new file mode 100644 index 0000000000..1054d721bc --- /dev/null +++ b/ansible/roles/memcached/handlers/main.yml @@ -0,0 +1,14 @@ +- name: Restart memcached container + vars: + service: "{{ memcached_services.memcached }}" + kolla_docker: + action: "start_container" + common_options: "{{ docker_common_options }}" + image: "{{ service.image }}" + name: "{{ service.container_name }}" + volumes: "{{ service.volumes }}" + when: + - inventory_hostname in groups[service.group] + - service.enabled | bool + - memcached_config_json.changed | bool + or check_memcached_container.changed | bool diff --git a/ansible/roles/memcached/tasks/config.yml b/ansible/roles/memcached/tasks/config.yml index f721633c7d..5a80ad9ab3 100644 --- a/ansible/roles/memcached/tasks/config.yml +++ b/ansible/roles/memcached/tasks/config.yml @@ -11,5 +11,22 @@ template: src: "{{ item }}.json.j2" dest: "{{ node_config_directory }}/{{ item }}/config.json" + register: memcached_config_json with_items: - "memcached" + notify: Restart memcached container + +- name: Check memcached container + vars: + service: "{{ memcached_services.memcached }}" + kolla_docker: + action: "compare_container" + common_options: "{{ docker_common_options }}" + name: "{{ service.container_name }}" + image: "{{ service.image }}" + volumes: "{{ service.volumes }}" + register: check_memcached_container + when: + - inventory_hostname in groups[service.group] + - service.enabled | bool + notify: Restart memcached container diff --git a/ansible/roles/memcached/tasks/deploy.yml b/ansible/roles/memcached/tasks/deploy.yml index 1f16915ad9..1317d110c3 100644 --- a/ansible/roles/memcached/tasks/deploy.yml +++ b/ansible/roles/memcached/tasks/deploy.yml @@ -1,4 +1,2 @@ --- - include: config.yml - -- include: start.yml diff --git a/ansible/roles/memcached/tasks/pull.yml b/ansible/roles/memcached/tasks/pull.yml index 1f8a639e83..f7827a6c52 100644 --- a/ansible/roles/memcached/tasks/pull.yml +++ b/ansible/roles/memcached/tasks/pull.yml @@ -1,7 +1,11 @@ --- - name: Pulling memcached image + vars: + service: "{{ memcached_services.memcached }}" kolla_docker: action: "pull_image" common_options: "{{ docker_common_options }}" - image: "{{ memcached_image_full }}" - when: inventory_hostname in groups['memcached'] + image: "{{ service.image }}" + when: + - inventory_hostname in groups[service.group] + - service.enabled | bool diff --git a/ansible/roles/memcached/tasks/reconfigure.yml b/ansible/roles/memcached/tasks/reconfigure.yml deleted file mode 100644 index b63684beb7..0000000000 --- a/ansible/roles/memcached/tasks/reconfigure.yml +++ /dev/null @@ -1,64 +0,0 @@ ---- -- 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: memcached, group: memcached } - -- 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: memcached, group: memcached } - -# 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: memcached, group: memcached } - -- 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: memcached, group: memcached }] - - "{{ 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: memcached, group: memcached }] - - "{{ container_envs.results }}" - - "{{ check_results.results }}" diff --git a/ansible/roles/memcached/tasks/reconfigure.yml b/ansible/roles/memcached/tasks/reconfigure.yml new file mode 120000 index 0000000000..0412f92200 --- /dev/null +++ b/ansible/roles/memcached/tasks/reconfigure.yml @@ -0,0 +1 @@ +deploy.yml \ No newline at end of file diff --git a/ansible/roles/memcached/tasks/start.yml b/ansible/roles/memcached/tasks/start.yml deleted file mode 100644 index c1a193f40f..0000000000 --- a/ansible/roles/memcached/tasks/start.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Starting memcached container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ memcached_image_full }}" - name: "memcached" - volumes: - - "{{ node_config_directory }}/memcached/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - when: inventory_hostname in groups['memcached'] diff --git a/ansible/roles/memcached/tasks/upgrade.yml b/ansible/roles/memcached/tasks/upgrade.yml index 1f16915ad9..1317d110c3 100644 --- a/ansible/roles/memcached/tasks/upgrade.yml +++ b/ansible/roles/memcached/tasks/upgrade.yml @@ -1,4 +1,2 @@ --- - include: config.yml - -- include: start.yml