diff --git a/ansible/roles/vmtp/defaults/main.yml b/ansible/roles/vmtp/defaults/main.yml index 58999df51b9e89ebaeec02c44f1bd47ea419aa83..11ef90c5ab0b659fdc146d9915c4d072b79c7227 100644 --- a/ansible/roles/vmtp/defaults/main.yml +++ b/ansible/roles/vmtp/defaults/main.yml @@ -1,6 +1,18 @@ --- project_name: "vmtp" +vmtp_services: + vmtp: + container_name: "vmtp" + image: "{{ vmtp_image_full }}" + enabled: true + group: "vmtp" + volumes: + - "{{ node_config_directory }}/vmtp/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla" + + #################### # Docker #################### diff --git a/ansible/roles/vmtp/handlers/main.yml b/ansible/roles/vmtp/handlers/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..abc8fe1a69572b61fd5000ad094a0205b6690b5e --- /dev/null +++ b/ansible/roles/vmtp/handlers/main.yml @@ -0,0 +1,17 @@ +- name: Restart vmtp container + vars: + service_name: "vmtp" + service: "{{ vmtp_services[service_name] }}" + vmtp_container: "{{ check_vmtp_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 + - vmtp_confs.changed | bool + or vmtp_container.changed | bool diff --git a/ansible/roles/vmtp/tasks/config.yml b/ansible/roles/vmtp/tasks/config.yml index c63c93e806d860765697c307038747affba2d6b8..b62b70900749c3f4c1bce85313a30a001605d6bb 100644 --- a/ansible/roles/vmtp/tasks/config.yml +++ b/ansible/roles/vmtp/tasks/config.yml @@ -1,9 +1,13 @@ --- - name: Ensuring config directories exist file: - path: "{{ node_config_directory }}/vmtp" + path: "{{ node_config_directory }}/{{ item.key }}" state: "directory" recurse: yes + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ vmtp_services }}" - name: Register binary python path command: echo /usr/lib/python2.7/site-packages @@ -16,11 +20,35 @@ when: kolla_install_type != 'binary' - name: Copying over configuration file for vmtp + vars: + service: "{{ vmtp_services['vmtp'] }}" merge_yaml: sources: - "{{ role_path }}/templates/{{ item }}.j2" - "{{ node_custom_config }}/{{ item }}" - "{{ node_custom_config }}/vmtp/{{ item }}" dest: "{{ python_path }}/vmtp/{{ item }}" + register: vmtp_confs + when: + - inventory_hostname in groups[service.group] + - service.enabled | bool with_items: - "cfg.default.yaml" + notify: + - Restart vmtp container + +- name: Check vmtp 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_vmtp_containers + when: + - action != "config" + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ vmtp_services }}" + notify: + - Restart vmtp container diff --git a/ansible/roles/vmtp/tasks/deploy.yml b/ansible/roles/vmtp/tasks/deploy.yml index d4daf108c129d5f252d9c80077572d3b1bea3796..5268b68025ad3b3bddd6afa84e87ea695b75a9c9 100644 --- a/ansible/roles/vmtp/tasks/deploy.yml +++ b/ansible/roles/vmtp/tasks/deploy.yml @@ -2,5 +2,5 @@ - include: config.yml when: inventory_hostname in groups['vmtp'] -- include: start.yml - when: inventory_hostname in groups['vmtp'] +- name: Flush handlers + meta: flush_handlers diff --git a/ansible/roles/vmtp/tasks/pull.yml b/ansible/roles/vmtp/tasks/pull.yml index 0be3c5eece500e193704550406fd6a33e8ae8ce0..dc06d6d812be0f9baef40bf9b7b0ed41123335af 100644 --- a/ansible/roles/vmtp/tasks/pull.yml +++ b/ansible/roles/vmtp/tasks/pull.yml @@ -3,5 +3,8 @@ kolla_docker: action: "pull_image" common_options: "{{ docker_common_options }}" - image: "{{ vmtp_image_full }}" - when: inventory_hostname in groups['vmtp'] + image: "{{ item.value.image }}" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ vmtp_services }}" diff --git a/ansible/roles/vmtp/tasks/reconfigure.yml b/ansible/roles/vmtp/tasks/reconfigure.yml index 3cf5f29402f42b07f5e1ba9d3f487351ccf84e0d..e078ef1318f52fd9e74ccb13343015761312ca52 100644 --- a/ansible/roles/vmtp/tasks/reconfigure.yml +++ b/ansible/roles/vmtp/tasks/reconfigure.yml @@ -1,58 +1,2 @@ --- -- name: Ensure container is up - kolla_docker: - name: "vmtp" - action: "get_container_state" - register: container_state - failed_when: container_state.Running == false - when: inventory_hostname in groups['vmtp'] - -- include: config.yml - -- name: Check configuration - 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['vmtp'] - with_items: - - { name: vmtp, group: vmtp } - -# 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: "vmtp" - action: "get_container_env" - register: container_envs - when: inventory_hostname in groups['vmtp'] - -- name: Remove the containers - kolla_docker: - name: "vmtp" - action: "remove_container" - register: remove_containers - when: - - config_strategy == "COPY_ONCE" or item[0]['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE' - - item[1]['rc'] == 1 - - inventory_hostname in groups['vmtp'] - with_together: - - "{{ container_envs.results }}" - - "{{ check_results.results }}" - -- include: start.yml - when: remove_containers.changed - -- name: Restart containers - kolla_docker: - name: "vmtp" - action: "restart_container" - when: - - config_strategy == 'COPY_ALWAYS' - - item[0]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE' - - item[1]['rc'] == 1 - - inventory_hostname in groups['vmtp'] - with_together: - - "{{ container_envs.results }}" - - "{{ check_results.results }}" +- include: deploy.yml diff --git a/ansible/roles/vmtp/tasks/start.yml b/ansible/roles/vmtp/tasks/start.yml deleted file mode 100644 index c3a2b19b73f52e2a05827e24012ccc4397268366..0000000000000000000000000000000000000000 --- a/ansible/roles/vmtp/tasks/start.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Starting vmtp container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ vmtp_image_full }}" - name: "vmtp" - volumes: - - "{{ node_config_directory }}/vmtp/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla" diff --git a/ansible/roles/vmtp/tasks/upgrade.yml b/ansible/roles/vmtp/tasks/upgrade.yml index 1f16915ad9228fe42472e2874f1dc854d2396daa..dd26ecc34d1b04e0a53cac19bc7751e77576b083 100644 --- a/ansible/roles/vmtp/tasks/upgrade.yml +++ b/ansible/roles/vmtp/tasks/upgrade.yml @@ -1,4 +1,5 @@ --- - include: config.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers