diff --git a/ansible/roles/cinder/defaults/main.yml b/ansible/roles/cinder/defaults/main.yml index 02a79e9cb2..f579a05d24 100644 --- a/ansible/roles/cinder/defaults/main.yml +++ b/ansible/roles/cinder/defaults/main.yml @@ -1,6 +1,52 @@ --- project_name: "cinder" +cinder_services: + cinder-api: + container_name: cinder_api + group: cinder-api + enabled: true + image: "{{ cinder_api_image_full }}" + volumes: + - "{{ node_config_directory }}/cinder-api/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + cinder-scheduler: + container_name: cinder_scheduler + group: cinder-scheduler + enabled: true + image: "{{ cinder_scheduler_image_full }}" + volumes: + - "{{ node_config_directory }}/cinder-scheduler/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + cinder-volume: + container_name: cinder_volume + group: cinder-volume + enabled: true + image: "{{ cinder_volume_image_full }}" + volumes: + - "{{ node_config_directory }}/cinder-volume/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "/dev/:/dev/" + - "/run/:/run/:shared" + - "{% if enable_iscsid | bool %}cinder:/var/lib/cinder{% endif %}" + - "{% if enable_iscsid | bool %}iscsi_info:/etc/iscsi{% endif %}" + - "kolla_logs:/var/log/kolla/" + cinder-backup: + container_name: cinder_backup + group: cinder-backup + enabled: true + image: "{{ cinder_backup_image_full }}" + volumes: + - "{{ node_config_directory }}/cinder-backup/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "/dev/:/dev/" + - "/run/:/run/:shared" + - "{% if enable_cinder_backend_lvm | bool %}cinder:/var/lib/cinder{% endif %}" + - "{% if enable_cinder_backend_lvm | bool %}iscsi_info:/etc/iscsi{% endif %}" + - "kolla_logs:/var/log/kolla/" + #################### # Ceph #################### diff --git a/ansible/roles/cinder/handlers/main.yml b/ansible/roles/cinder/handlers/main.yml new file mode 100644 index 0000000000..dbf5d97b9c --- /dev/null +++ b/ansible/roles/cinder/handlers/main.yml @@ -0,0 +1,92 @@ +--- +- name: Restart cinder-api container + vars: + service_name: "cinder-api" + service: "{{ cinder_services[service_name] }}" + config_json: "{{ cinder_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + cinder_conf: "{{ cinder_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + policy_json: "{{ cinder_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + cinder_api_container: "{{ check_cinder_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 cinder_conf.changed | bool + or policy_json.changed | bool + or cinder_api_container.changed | + +- name: Restart cinder-scheduler container + vars: + service_name: "cinder-scheduler" + service: "{{ cinder_services[service_name] }}" + config_json: "{{ cinder_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + cinder_conf: "{{ cinder_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + policy_json: "{{ cinder_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + cinder_scheduler_container: "{{ check_cinder_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 cinder_conf.changed | bool + or policy_json.changed | bool + or cinder_scheduler_container.changed | bool + +- name: Restart cinder-volume container + vars: + service_name: "cinder-volume" + service: "{{ cinder_services[service_name] }}" + config_json: "{{ cinder_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + cinder_conf: "{{ cinder_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + policy_json: "{{ cinder_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + cinder_volume_container: "{{ check_cinder_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 cinder_conf.changed | bool + or policy_json.changed | bool + or cinder_volume_container.changed | bool + +- name: Restart cinder-backup container + vars: + service_name: "cinder-backup" + service: "{{ cinder_services[service_name] }}" + config_json: "{{ cinder_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + cinder_conf: "{{ cinder_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + policy_json: "{{ cinder_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + cinder_backup_container: "{{ check_cinder_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 cinder_conf.changed | bool + or policy_json.changed | bool + or cinder_backup_container.changed | bool diff --git a/ansible/roles/cinder/tasks/bootstrap_service.yml b/ansible/roles/cinder/tasks/bootstrap_service.yml index 7968f466c9..b83865dd19 100644 --- a/ansible/roles/cinder/tasks/bootstrap_service.yml +++ b/ansible/roles/cinder/tasks/bootstrap_service.yml @@ -1,5 +1,7 @@ --- - name: Running Cinder bootstrap container + vars: + cinder_api: "{{ cinder_services['cinder-api'] }}" kolla_docker: action: "start_container" common_options: "{{ docker_common_options }}" @@ -7,14 +9,11 @@ environment: KOLLA_BOOTSTRAP: KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - image: "{{ cinder_api_image_full }}" + image: "{{ cinder_api.image }}" labels: BOOTSTRAP: name: "bootstrap_cinder" restart_policy: "never" - volumes: - - "{{ node_config_directory }}/cinder-api/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" + volumes: "{{ cinder_api.volumes }}" run_once: True - delegate_to: "{{ groups['cinder-api'][0] }}" + delegate_to: "{{ groups[cinder_api.group][0] }}" diff --git a/ansible/roles/cinder/tasks/config.yml b/ansible/roles/cinder/tasks/config.yml index db9d42ea13..b64164ba84 100644 --- a/ansible/roles/cinder/tasks/config.yml +++ b/ansible/roles/cinder/tasks/config.yml @@ -1,43 +1,52 @@ --- - name: Ensuring config directories exist file: - path: "{{ node_config_directory }}/{{ item }}" + path: "{{ node_config_directory }}/{{ item.key }}" state: "directory" recurse: yes - with_items: - - "cinder-api" - - "cinder-backup" - - "cinder-scheduler" - - "cinder-volume" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ cinder_services }}" - name: Copying over config.json files for services template: - src: "{{ item }}.json.j2" - dest: "{{ node_config_directory }}/{{ item }}/config.json" - with_items: - - "cinder-api" - - "cinder-backup" - - "cinder-scheduler" - - "cinder-volume" + src: "{{ item.key }}.json.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/config.json" + register: cinder_config_jsons + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ cinder_services }}" + notify: + - Restart cinder-api container + - Restart cinder-scheduler container + - Restart cinder-volume container + - Restart cinder-backup container - name: Copying over cinder.conf merge_configs: vars: - service_name: "{{ item }}" + service_name: "{{ item.key }}" sources: - "{{ role_path }}/templates/cinder.conf.j2" - "{{ node_custom_config }}/global.conf" - "{{ node_custom_config }}/database.conf" - "{{ node_custom_config }}/messaging.conf" - "{{ node_custom_config }}/cinder.conf" - - "{{ node_custom_config }}/cinder/{{ item }}.conf" + - "{{ node_custom_config }}/cinder/{{ item.key }}.conf" - "{{ node_custom_config }}/cinder/{{ inventory_hostname }}/cinder.conf" - dest: "{{ node_config_directory }}/{{ item }}/cinder.conf" - with_items: - - "cinder-api" - - "cinder-backup" - - "cinder-scheduler" - - "cinder-volume" + dest: "{{ node_config_directory }}/{{ item.key }}/cinder.conf" + register: cinder_confs + when: + - item.value.enabled | bool + - inventory_hostname in groups[item.value.group] + with_dict: "{{ cinder_services }}" + notify: + - Restart cinder-api container + - Restart cinder-scheduler container + - Restart cinder-volume container + - Restart cinder-backup container - name: Check if policies shall be overwritten local_action: stat path="{{ node_custom_config }}/cinder/policy.json" @@ -46,18 +55,21 @@ - name: Copying over existing policy.json template: src: "{{ node_custom_config }}/cinder/policy.json" - dest: "{{ node_config_directory }}/{{ item }}/policy.json" - with_items: - - "cinder-api" - - "cinder-backup" - - "cinder-scheduler" - - "cinder-volume" + dest: "{{ node_config_directory }}/{{ item.key }}/policy.json" + register: cinder_policy_jsons when: - cinder_policy.stat.exists + - cinder_policy.stat.exists + - inventory_hostname in groups[item.value.group] + with_dict: "{{ cinder_services }}" + notify: + - Restart cinder-api container + - Restart cinder-scheduler container + - Restart cinder-volume container + - Restart cinder-backup container - name: Copying over nfs_shares files for cinder_volume template: - src: "{{ item }}" + src: "{{ item.key }}" dest: "{{ node_config_directory }}/cinder-volume/nfs_shares" with_first_found: - files: @@ -66,3 +78,22 @@ - "{{ node_custom_config }}/cinder/cinder-volume/nfs_shares.j2" - "{{ node_custom_config }}/cinder/{{ inventory_hostname }}/nfs_shares.j2" skip: "{{ not enable_cinder_backend_nfs | bool and not enable_cinder_backend_hnas_nfs | bool }}" + +- name: Check cinder 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_cinder_containers + when: + - action != "config" + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ cinder_services }}" + notify: + - Restart cinder-api container + - Restart cinder-scheduler container + - Restart cinder-volume container + - Restart cinder-backup container diff --git a/ansible/roles/cinder/tasks/deploy.yml b/ansible/roles/cinder/tasks/deploy.yml index b01e2efae8..d3c6a0dab0 100644 --- a/ansible/roles/cinder/tasks/deploy.yml +++ b/ansible/roles/cinder/tasks/deploy.yml @@ -26,11 +26,8 @@ - include: bootstrap.yml when: inventory_hostname in groups['cinder-api'] -- include: start.yml - when: inventory_hostname in groups['cinder-api'] or - inventory_hostname in groups['cinder-volume'] or - inventory_hostname in groups['cinder-scheduler'] or - inventory_hostname in groups['cinder-backup'] +- name: Flush handlers + meta: flush_handlers - include: check.yml when: inventory_hostname in groups['cinder-api'] or diff --git a/ansible/roles/cinder/tasks/pull.yml b/ansible/roles/cinder/tasks/pull.yml index 6e2249f2df..2e80e16c11 100644 --- a/ansible/roles/cinder/tasks/pull.yml +++ b/ansible/roles/cinder/tasks/pull.yml @@ -1,28 +1,10 @@ --- -- name: Pulling cinder-api image +- name: Pulling cinder images kolla_docker: action: "pull_image" common_options: "{{ docker_common_options }}" - image: "{{ cinder_api_image_full }}" - when: inventory_hostname in groups['cinder-api'] - -- name: Pulling cinder-backup image - kolla_docker: - action: "pull_image" - common_options: "{{ docker_common_options }}" - image: "{{ cinder_backup_image_full }}" - when: inventory_hostname in groups['cinder-backup'] - -- name: Pulling cinder-scheduler image - kolla_docker: - action: "pull_image" - common_options: "{{ docker_common_options }}" - image: "{{ cinder_scheduler_image_full }}" - when: inventory_hostname in groups['cinder-scheduler'] - -- name: Pulling cinder-volume image - kolla_docker: - action: "pull_image" - common_options: "{{ docker_common_options }}" - image: "{{ cinder_volume_image_full }}" - when: inventory_hostname in groups['cinder-volume'] + image: "{{ item.value.image }}" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ cinder_services }}" diff --git a/ansible/roles/cinder/tasks/reconfigure.yml b/ansible/roles/cinder/tasks/reconfigure.yml index af453c8875..e078ef1318 100644 --- a/ansible/roles/cinder/tasks/reconfigure.yml +++ b/ansible/roles/cinder/tasks/reconfigure.yml @@ -1,79 +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: cinder_api, group: cinder-api } - - { name: cinder_scheduler, group: cinder-scheduler } - - { name: cinder_volume, group: cinder-volume } - - { name: cinder_backup, group: cinder-backup } - -- 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: cinder_api, group: cinder-api } - - { name: cinder_scheduler, group: cinder-scheduler } - - { name: cinder_volume, group: cinder-volume } - - { name: cinder_backup, group: cinder-backup } - -# 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: cinder_api, group: cinder-api } - - { name: cinder_scheduler, group: cinder-scheduler } - - { name: cinder_volume, group: cinder-volume } - - { name: cinder_backup, group: cinder-backup } - -- 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: cinder_api, group: cinder-api }, - { name: cinder_scheduler, group: cinder-scheduler }, - { name: cinder_volume, group: cinder-volume }, - { name: cinder_backup, group: cinder-backup }] - - "{{ 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: cinder_api, group: cinder-api }, - { name: cinder_scheduler, group: cinder-scheduler }, - { name: cinder_volume, group: cinder-volume }, - { name: cinder_backup, group: cinder-backup }] - - "{{ container_envs.results }}" - - "{{ check_results.results }}" +- include: deploy.yml diff --git a/ansible/roles/cinder/tasks/start.yml b/ansible/roles/cinder/tasks/start.yml deleted file mode 100644 index 2ed3515f3b..0000000000 --- a/ansible/roles/cinder/tasks/start.yml +++ /dev/null @@ -1,67 +0,0 @@ ---- -- name: Starting cinder-api container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - name: "cinder_api" - image: "{{ cinder_api_image_full }}" - volumes: - - "{{ node_config_directory }}/cinder-api/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - when: inventory_hostname in groups['cinder-api'] - -- name: Starting cinder-scheduler container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - name: "cinder_scheduler" - image: "{{ cinder_scheduler_image_full }}" - volumes: - - "{{ node_config_directory }}/cinder-scheduler/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - when: inventory_hostname in groups['cinder-scheduler'] - -- name: Prepare volumes list for cinder-volume - set_fact: - cinder_volume_mounts: - - "{{ node_config_directory }}/cinder-volume/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "/dev/:/dev/" - - "/run/:/run/:shared" - - "{% if enable_iscsid | bool %}cinder:/var/lib/cinder{% endif %}" - - "{% if enable_iscsid | bool %}iscsi_info:/etc/iscsi{% endif %}" - - "kolla_logs:/var/log/kolla/" - -- name: Starting cinder-volume container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - name: "cinder_volume" - image: "{{ cinder_volume_image_full }}" - privileged: True - ipc_mode: "host" - volumes: '{{ cinder_volume_mounts | reject("equalto", "") | list }}' - when: inventory_hostname in groups['cinder-volume'] - -- name: Prepare volumes list for cinder-backup - set_fact: - cinder_backup_mounts: - - "{{ node_config_directory }}/cinder-backup/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "/dev/:/dev/" - - "/run/:/run/:shared" - - "{% if enable_cinder_backend_lvm | bool %}cinder:/var/lib/cinder{% endif %}" - - "{% if enable_cinder_backend_lvm | bool %}iscsi_info:/etc/iscsi{% endif %}" - - "kolla_logs:/var/log/kolla/" - -- name: Starting cinder-backup container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - name: "cinder_backup" - image: "{{ cinder_backup_image_full }}" - privileged: True - volumes: '{{ cinder_backup_mounts | reject("equalto", "") | list }}' - when: inventory_hostname in groups['cinder-backup'] diff --git a/ansible/roles/cinder/tasks/upgrade.yml b/ansible/roles/cinder/tasks/upgrade.yml index 308053080c..c38db1adf4 100644 --- a/ansible/roles/cinder/tasks/upgrade.yml +++ b/ansible/roles/cinder/tasks/upgrade.yml @@ -3,4 +3,5 @@ - include: bootstrap_service.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers