Optimize reconfiguration for barbican

Change-Id: I0808b32115989ed55bf5401d2f5401930766d39a
Partially-implements: blueprint better-reconfigure
This commit is contained in:
caoyuan 2017-01-22 10:06:06 +08:00
parent 686bf67681
commit 91dbe0ec0c
9 changed files with 175 additions and 158 deletions

View File

@ -1,6 +1,35 @@
--- ---
project_name: "barbican" project_name: "barbican"
barbican_services:
barbican-api:
container_name: barbican_api
group: barbican-api
enabled: true
image: "{{ barbican_api_image_full }}"
volumes:
- "{{ node_config_directory }}/barbican-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "barbican:/var/lib/barbican/"
- "kolla_logs:/var/log/kolla/"
barbican-keystone-listener:
container_name: barbican_keystone_listener
group: barbican-keystone-listener
enabled: true
image: "{{ barbican_keystone_listener_image_full }}"
volumes:
- "{{ node_config_directory }}/barbican-keystone-listener/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
barbican-worker:
container_name: barbican_worker
group: barbican-worker
enabled: true
image: "{{ barbican_worker_image_full }}"
volumes:
- "{{ node_config_directory }}/barbican-worker/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
#################### ####################
# Database # Database

View File

@ -0,0 +1,71 @@
---
- name: Restart barbican-api container
vars:
service_name: "barbican-api"
service: "{{ barbican_services[service_name] }}"
config_json: "{{ barbican_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
barbican_conf: "{{ barbican_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ barbican_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
barbican_api_container: "{{ check_barbican_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 barbican_conf.changed | bool
or policy_json.changed | bool
or barbican_api_ini.changed | bool
or barbican_api_paste.changed | bool
or barbican_api_container.changed | bool
- name: Restart barbican-keystone-listener container
vars:
service_name: "barbican-keystone-listener"
service: "{{ barbican_services[service_name] }}"
config_json: "{{ barbican_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
barbican_conf: "{{ barbican_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ barbican_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
barbican_keystone_listener_container: "{{ check_barbican_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 barbican_conf.changed | bool
or policy_json.changed | bool
or barbican_keystone_listener_container.changed | bool
- name: Restart barbican-worker container
vars:
service_name: "barbican-worker"
service: "{{ barbican_services[service_name] }}"
config_json: "{{ barbican_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
barbican_conf: "{{ barbican_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ barbican_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
barbican_worker_container: "{{ check_barbican_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 barbican_conf.changed | bool
or policy_json.changed | bool
or barbican_worker_container.changed | bool

View File

@ -1,5 +1,7 @@
--- ---
- name: Running barbican bootstrap container - name: Running barbican bootstrap container
vars:
barbican_api: "{{ barbican_services['barbican-api'] }}"
kolla_docker: kolla_docker:
action: "start_container" action: "start_container"
common_options: "{{ docker_common_options }}" common_options: "{{ docker_common_options }}"
@ -7,15 +9,11 @@
environment: environment:
KOLLA_BOOTSTRAP: KOLLA_BOOTSTRAP:
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
image: "{{ barbican_api_image_full }}" image: "{{ barbican_api.image }}"
labels: labels:
BOOTSTRAP: BOOTSTRAP:
name: "bootstrap_barbican" name: "bootstrap_barbican"
restart_policy: "never" restart_policy: "never"
volumes: volumes: "{{ barbican_api.volumes }}"
- "{{ node_config_directory }}/barbican-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "barbican:/var/lib/barbican/"
- "kolla_logs:/var/log/kolla/"
run_once: True run_once: True
delegate_to: "{{ groups['barbican-api'][0] }}" delegate_to: "{{ groups[barbican_api.group][0] }}"

View File

@ -11,46 +11,68 @@
- 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: barbican_config_jsons
- "barbican-api" when:
- "barbican-worker" - inventory_hostname in groups[item.value.group]
- "barbican-keystone-listener" - item.value.enabled | bool
with_dict: "{{ barbican_services }}"
notify:
- Restart {{ item.key }} container
- name: Copying over barbican-api.ini - name: Copying over barbican-api.ini
vars:
service: "{{ barbican_services['barbican-api'] }}"
merge_configs: merge_configs:
sources: sources:
- "{{ role_path }}/templates/barbican-api.ini.j2" - "{{ role_path }}/templates/barbican-api.ini.j2"
- "{{ node_custom_config }}/barbican-api/barbican-api.ini" - "{{ node_custom_config }}/barbican-api/barbican-api.ini"
- "{{ node_custom_config }}/barbican-api/{{ inventory_hostname }}/barbican-api.ini" - "{{ node_custom_config }}/barbican-api/{{ inventory_hostname }}/barbican-api.ini"
dest: "{{ node_config_directory }}/barbican-api/vassals/barbican-api.ini" dest: "{{ node_config_directory }}/barbican-api/vassals/barbican-api.ini"
register: barbican_api_ini
when:
- inventory_hostname in groups['barbican-api']
- service.enabled | bool
notify:
- Restart barbican-api container
- name: Copying over barbican-api-paste.ini - name: Copying over barbican-api-paste.ini
vars:
service: "{{ barbican_services['barbican-api'] }}"
merge_configs: merge_configs:
sources: sources:
- "{{ role_path }}/templates/barbican-api-paste.ini.j2" - "{{ role_path }}/templates/barbican-api-paste.ini.j2"
- "{{ node_custom_config }}/barbican-api/barbican-api-paste.ini" - "{{ node_custom_config }}/barbican-api/barbican-api-paste.ini"
- "{{ node_custom_config }}/barbican-api/{{ inventory_hostname }}/barbican-api-paste.ini" - "{{ node_custom_config }}/barbican-api/{{ inventory_hostname }}/barbican-api-paste.ini"
dest: "{{ node_config_directory }}/barbican-api/barbican-api-paste.ini" dest: "{{ node_config_directory }}/barbican-api/barbican-api-paste.ini"
when:
- inventory_hostname in groups['barbiacn-api']
- service.enabled | bool
register: barbican_api_paste
notify:
- Restart barbican-api container
- name: Copying over barbican.conf - name: Copying over barbican.conf
merge_configs: merge_configs:
vars: vars:
service_name: "{{ item }}" service_name: "{{ item.key }}"
sources: sources:
- "{{ role_path }}/templates/barbican.conf.j2" - "{{ role_path }}/templates/barbican.conf.j2"
- "{{ node_custom_config }}/global.conf" - "{{ node_custom_config }}/global.conf"
- "{{ node_custom_config }}/database.conf" - "{{ node_custom_config }}/database.conf"
- "{{ node_custom_config }}/messaging.conf" - "{{ node_custom_config }}/messaging.conf"
- "{{ node_custom_config }}/barbican.conf" - "{{ node_custom_config }}/barbican.conf"
- "{{ node_custom_config }}/barbican/{{ item }}.conf" - "{{ node_custom_config }}/barbican/{{ item.key }}.conf"
- "{{ node_custom_config }}/barbican/{{ inventory_hostname }}/barbican.conf" - "{{ node_custom_config }}/barbican/{{ inventory_hostname }}/barbican.conf"
dest: "{{ node_config_directory }}/{{ item }}/barbican.conf" dest: "{{ node_config_directory }}/{{ item.key }}/barbican.conf"
with_items: register: barbican_confs
- "barbican-api" when:
- "barbican-keystone-listener" - item.value.enabled | bool
- "barbican-worker" - inventory_hostname in groups[item.value.group]
with_dict: "{{ barbican_services }}"
notify:
- Restart {{ item.key }} container
- name: Check if policies shall be overwritten - name: Check if policies shall be overwritten
local_action: stat path="{{ node_custom_config }}/barbican/policy.json" local_action: stat path="{{ node_custom_config }}/barbican/policy.json"
@ -59,10 +81,28 @@
- name: Copying over existing policy.json - name: Copying over existing policy.json
template: template:
src: "{{ node_custom_config }}/barbican/policy.json" src: "{{ node_custom_config }}/barbican/policy.json"
dest: "{{ node_config_directory }}/{{ item }}/policy.json" dest: "{{ node_config_directory }}/{{ item.key }}/policy.json"
with_items: register: barbican_policy_jsons
- "barbican-api"
- "barbican-keystone-listener"
- "barbican-worker"
when: when:
barbican_policy.stat.exists - barbican_policy.stat.exists
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ barbican_services }}"
notify:
- Restart {{ item.key }} container
- name: Check barbican 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_barbican_containers
when:
- action != "config"
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ barbican_services }}"
notify:
- Restart {{ item.key }} container

View File

@ -10,7 +10,5 @@
- include: bootstrap.yml - include: bootstrap.yml
when: inventory_hostname in groups['barbican-api'] when: inventory_hostname in groups['barbican-api']
- include: start.yml - name: Flush handlers
when: inventory_hostname in groups['barbican-api'] or meta: flush_handlers
inventory_hostname in groups['barbican-worker'] or
inventory_hostname in groups['barbican-keystone-listener']

View File

@ -1,21 +1,10 @@
--- ---
- name: Pulling barbican-api image - name: Pulling barbican images
kolla_docker: kolla_docker:
action: "pull_image" action: "pull_image"
common_options: "{{ docker_common_options }}" common_options: "{{ docker_common_options }}"
image: "{{ barbican_api_image_full }}" image: "{{ item.value.image }}"
when: inventory_hostname in groups['barbican-api'] when:
- inventory_hostname in groups[item.value.group]
- name: Pulling barbican-keystone-listener image - item.value.enabled | bool
kolla_docker: with_dict: "{{ barbican_services }}"
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ barbican_keystone_listener_image_full }}"
when: inventory_hostname in groups['barbican-keystone-listener']
- name: Pulling barbican-worker image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ barbican_worker_image_full }}"
when: inventory_hostname in groups['barbican-worker']

View File

@ -1,74 +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: barbican_api, group: barbican-api }
- { name: barbican_keystone_listener, group: barbican-keystone-listener }
- { name: barbican_worker, group: barbican-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: barbican_api, group: barbican-api }
- { name: barbican_keystone_listener, group: barbican-keystone-listener }
- { name: barbican_worker, group: barbican-worker }
# 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: barbican_api, group: barbican-api }
- { name: barbican_keystone_listener, group: barbican-keystone-listener }
- { name: barbican_worker, group: barbican-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: barbican_api, group: barbican-api },
{ name: barbican_keystone_listener, group: barbican-keystone-listener },
{ name: barbican_worker, group: barbican-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: barbican_api, group: barbican-api },
{ name: barbican_keystone_listener, group: barbican-keystone-listener },
{ name: barbican_worker, group: barbican-worker }]
- "{{ container_envs.results }}"
- "{{ check_results.results }}"

View File

@ -1,37 +0,0 @@
---
- name: Starting barbican-api container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ barbican_api_image_full }}"
name: "barbican_api"
volumes:
- "{{ node_config_directory }}/barbican-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "barbican:/var/lib/barbican/"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['barbican-api']
- name: Starting barbican-keystone-listener container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ barbican_keystone_listener_image_full }}"
name: "barbican_keystone_listener"
volumes:
- "{{ node_config_directory }}/barbican-keystone-listener/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['barbican-keystone-listener']
- name: Starting barbican-worker container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ barbican_worker_image_full }}"
name: "barbican_worker"
volumes:
- "{{ node_config_directory }}/barbican-worker/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['barbican-worker']

View File

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