Optimize reconfiguration for tacker

Change-Id: I5258b6e1384d75972b64a2b83d1913545b5af44d
Partically-implements: blueprint better-reconfigure
This commit is contained in:
Eduardo Gonzalez 2017-01-18 14:51:17 +00:00
parent 4357f6df38
commit cc149dd0c6
9 changed files with 96 additions and 99 deletions

View File

@ -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
####################

View File

@ -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

View File

@ -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] }}"

View File

@ -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

View File

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

View File

@ -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 }}"

View File

@ -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

View File

@ -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/"

View File

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