Merge "Optimize reconfigure action for rabbitmq"

This commit is contained in:
Jenkins 2017-05-23 11:24:04 +00:00 committed by Gerrit Code Review
commit 57f0a3c4a7
8 changed files with 83 additions and 87 deletions

View File

@ -1,6 +1,19 @@
--- ---
project_name: "rabbitmq" project_name: "rabbitmq"
rabbitmq_services:
rabbitmq:
container_name: rabbitmq
group: rabbitmq
enabled: true
image: "{{ rabbitmq_image_full }}"
volumes:
- "{{ node_config_directory }}/rabbitmq/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "rabbitmq:/var/lib/rabbitmq/"
- "kolla_logs:/var/log/kolla/"
#################### ####################
# Docker # Docker
#################### ####################

View File

@ -0,0 +1,20 @@
---
- name: Restart rabbitmq container
vars:
service_name: "rabbitmq"
service: "{{ rabbitmq_services[service_name] }}"
config_json: "{{ rabbitmq_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
rabbitmq_container: "{{ check_rabbitmq_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 rabbitmq_confs.changed | bool
or rabbitmq_container.changed | bool

View File

@ -1,25 +1,56 @@
--- ---
- name: Ensuring config directories exist - name: Ensuring config directories exist
file: file:
path: "{{ node_config_directory }}/{{ item }}" path: "{{ node_config_directory }}/{{ item.key }}"
state: "directory" state: "directory"
recurse: yes recurse: yes
with_items: when:
- "rabbitmq" - inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ rabbitmq_services }}"
- name: Copying over config.json files for services - name: Copying over config.json files for services
template: template:
src: "{{ item }}.json.j2" src: "{{ item.key }}.json.j2"
dest: "{{ node_config_directory }}/{{ item }}/config.json" dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
with_items: register: rabbitmq_config_jsons
- "rabbitmq" when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ rabbitmq_services }}"
notify:
- Restart rabbitmq container
- name: Copying over rabbitmq configs - name: Copying over rabbitmq configs
vars:
service: "{{ rabbitmq_services['rabbitmq'] }}"
template: template:
src: "{{ item }}.j2" src: "{{ item }}.j2"
dest: "{{ node_config_directory }}/rabbitmq/{{ item }}" dest: "{{ node_config_directory }}/rabbitmq/{{ item }}"
register: rabbitmq_confs
when:
- inventory_hostname in groups[service.group]
- service.enabled | bool
with_items: with_items:
- "rabbitmq-env.conf" - "rabbitmq-env.conf"
- "rabbitmq.config" - "rabbitmq.config"
- "rabbitmq-clusterer.config" - "rabbitmq-clusterer.config"
- "definitions.json" - "definitions.json"
notify:
- Restart rabbitmq container
- name: Check rabbitmq 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_rabbitmq_containers
when:
- action != "config"
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ rabbitmq_services }}"
notify:
- Restart rabbitmq container

View File

@ -3,4 +3,5 @@
- include: bootstrap.yml - include: bootstrap.yml
- include: start.yml - name: Flush handlers
meta: flush_handlers

View File

@ -3,5 +3,8 @@
kolla_docker: kolla_docker:
action: "pull_image" action: "pull_image"
common_options: "{{ docker_common_options }}" common_options: "{{ docker_common_options }}"
image: "{{ rabbitmq_image_full }}" image: "{{ item.value.image }}"
when: inventory_hostname in groups['rabbitmq'] when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ rabbitmq_services }}"

View File

@ -1,64 +1,2 @@
--- ---
- name: Ensuring the containers up - include: deploy.yml
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: rabbitmq, group: rabbitmq }
- 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: rabbitmq, group: rabbitmq }
# 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: rabbitmq, group: rabbitmq }
- 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: rabbitmq, group: rabbitmq }]
- "{{ 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: rabbitmq, group: rabbitmq }]
- "{{ container_envs.results }}"
- "{{ check_results.results }}"

View File

@ -1,12 +0,0 @@
---
- name: Starting rabbitmq container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ rabbitmq_image_full }}"
name: "rabbitmq"
volumes:
- "{{ node_config_directory }}/rabbitmq/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "rabbitmq:/var/lib/rabbitmq/"
- "kolla_logs:/var/log/kolla/"

View File

@ -26,12 +26,14 @@
- rabbitmq_hostname != (gospel_node.stdout | from_json).hostname - rabbitmq_hostname != (gospel_node.stdout | from_json).hostname
- rabbitmq_differs['result'] - rabbitmq_differs['result']
- include: start.yml - name: Flush handlers
meta: flush_handlers
when: when:
- rabbitmq_hostname == (gospel_node.stdout | from_json).hostname - rabbitmq_hostname == (gospel_node.stdout | from_json).hostname
- rabbitmq_differs['result'] - rabbitmq_differs['result']
- include: start.yml - name: Flush handlers
meta: flush_handlers
when: when:
- rabbitmq_hostname != (gospel_node.stdout | from_json).hostname - rabbitmq_hostname != (gospel_node.stdout | from_json).hostname
- rabbitmq_differs['result'] - rabbitmq_differs['result']