diff --git a/ansible/roles/kuryr/defaults/main.yml b/ansible/roles/kuryr/defaults/main.yml index 1c755b1c44..e8ffb97a5c 100644 --- a/ansible/roles/kuryr/defaults/main.yml +++ b/ansible/roles/kuryr/defaults/main.yml @@ -1,6 +1,25 @@ --- project_name: "kuryr" +# NOTE(huikang, apuimedo): when you request a driver in a docker operation, such +# as docker network create, docker searches /usr/lib/docker or /etc/docker +# subdirs for network/storage plugin specs or json definitions. so it's either +# have ansible place the file there, or volume mount it and let the container +# place the file there + +kuryr_services: + kuryr: + container_name: kuryr + group: compute + enabled: True + image: "{{ kuryr_image_full }}" + privileged: True + volumes: + - "{{ node_config_directory }}/kuryr/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "/run:/run:shared" + - "/usr/lib/docker:/usr/lib/docker" + #################### # Docker diff --git a/ansible/roles/kuryr/handlers/main.yml b/ansible/roles/kuryr/handlers/main.yml new file mode 100644 index 0000000000..84f8445da0 --- /dev/null +++ b/ansible/roles/kuryr/handlers/main.yml @@ -0,0 +1,25 @@ +--- +- name: Restart kuryr container + vars: + service_name: "kuryr" + service: "{{ kuryr_services[service_name] }}" + config_json: "{{ kuryr_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + kuryr_conf: "{{ kuryr_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + policy_json: "{{ kuryr_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + kuryr_container: "{{ check_kuryr_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 }}" + privileged: "{{ service.privileged | default(False) }}" + volumes: "{{ service.volumes }}" + when: + - action != "config" + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or kuryr_conf.changed | bool + or kuryr_spec.changed | bool + or policy_json.changed | bool + or kuryr_container.changed | bool diff --git a/ansible/roles/kuryr/tasks/bootstrap.yml b/ansible/roles/kuryr/tasks/bootstrap.yml index 0962484c24..c8fa0cff49 100644 --- a/ansible/roles/kuryr/tasks/bootstrap.yml +++ b/ansible/roles/kuryr/tasks/bootstrap.yml @@ -1,5 +1,7 @@ --- - name: Running Kuryr bootstrap container + vars: + kuryr: "{{ kuryr_services['kuryr'] }}" kolla_docker: action: "start_container" common_options: "{{ docker_common_options }}" @@ -7,13 +9,11 @@ environment: KOLLA_BOOTSTRAP: KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - image: "{{ kuryr_image_full }}" + image: "{{ kuryr.image }}" labels: BOOTSTRAP: name: "bootstrap_kuryr" restart_policy: "never" - volumes: - - "{{ node_config_directory }}/kuryr/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "/run:/run:shared" - - "/usr/lib/docker:/usr/lib/docker" + volumes: "{{ kuryr.volumes }}" + run_once: True + delegate_to: "{{ groups[kuryr.group][0] }}" diff --git a/ansible/roles/kuryr/tasks/config.yml b/ansible/roles/kuryr/tasks/config.yml index 001793780c..22e8154ef4 100644 --- a/ansible/roles/kuryr/tasks/config.yml +++ b/ansible/roles/kuryr/tasks/config.yml @@ -1,28 +1,61 @@ --- - name: Ensuring config directories exist file: - path: "{{ node_config_directory }}/{{ item }}" + path: "{{ node_config_directory }}/{{ item.key }}" state: "directory" recurse: yes - with_items: - - "kuryr" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ kuryr_services }}" - name: Copying over config.json files for services template: - src: "{{ item }}.json.j2" - dest: "{{ node_config_directory }}/{{ item }}/config.json" - with_items: - - "kuryr" + src: "{{ item.key }}.json.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/config.json" + register: kuryr_config_jsons + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ kuryr_services }}" + notify: + - Restart kuryr container - name: Copying over kuryr.conf - template: - src: "kuryr.conf.j2" - dest: "{{ node_config_directory }}/kuryr/kuryr.conf" + merge_configs: + vars: + service_name: "{{ item.key }}" + sources: + - "{{ role_path }}/templates/kuryr.conf.j2" + - "{{ node_custom_config }}/global.conf" + - "{{ node_custom_config }}/database.conf" + - "{{ node_custom_config }}/messaging.conf" + - "{{ node_custom_config }}/kuryr.conf" + - "{{ node_custom_config }}/kuryr/{{ item.key }}.conf" + - "{{ node_custom_config }}/kuryr/{{ inventory_hostname }}/{{ item.key }}.conf" + dest: "{{ node_config_directory }}/{{ item.key }}/kuryr.conf" + register: kuryr_confs + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ kuryr_services }}" + notify: + - Restart kuryr container - name: Copying over kuryr.spec + vars: + service: "{{ kuryr_services['kuryr']}}" template: src: "kuryr.spec.j2" - dest: "{{ node_config_directory }}/kuryr/kuryr.spec" + dest: "{{ node_config_directory }}/{{ item }}/kuryr.spec" + register: kuryr_spec + when: + - inventory_hostname in groups[service.group] + - service.enabled | bool + with_items: + - "kuryr" + notify: + - Restart kuryr container - name: Check if policies shall be overwritten local_action: stat path="{{ node_custom_config }}/kuryr/policy.json" @@ -31,6 +64,29 @@ - name: Copying over existing policy.json template: src: "{{ node_custom_config }}/kuryr/policy.json" - dest: "{{ node_config_directory }}/kuryr/policy.json" + dest: "{{ node_config_directory }}/{{ item.key }}/policy.json" + register: kuryr_policy_jsons when: - kuryr_policy.stat.exists + - kuryr_policy.stat.exists + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ kuryr_services }}" + notify: + - Restart kuryr container + +- name: Check kuryr containers + kolla_docker: + action: "compare_container" + common_options: "{{ docker_common_options }}" + name: "{{ item.value.container_name }}" + image: "{{ item.value.image }}" + privileged: "{{ item.value.privileged|default(False) }}" + volumes: "{{ item.value.volumes }}" + register: check_kuryr_containers + when: + - action != "config" + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ kuryr_services }}" + notify: + - Restart kuryr container diff --git a/ansible/roles/kuryr/tasks/deploy.yml b/ansible/roles/kuryr/tasks/deploy.yml index 5c48120b7c..864362ba5f 100644 --- a/ansible/roles/kuryr/tasks/deploy.yml +++ b/ansible/roles/kuryr/tasks/deploy.yml @@ -5,4 +5,5 @@ - include: bootstrap.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers diff --git a/ansible/roles/kuryr/tasks/reconfigure.yml b/ansible/roles/kuryr/tasks/reconfigure.yml new file mode 100644 index 0000000000..e078ef1318 --- /dev/null +++ b/ansible/roles/kuryr/tasks/reconfigure.yml @@ -0,0 +1,2 @@ +--- +- include: deploy.yml diff --git a/ansible/roles/kuryr/tasks/start.yml b/ansible/roles/kuryr/tasks/start.yml deleted file mode 100644 index fe93383bf3..0000000000 --- a/ansible/roles/kuryr/tasks/start.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -# NOTE(huikang, apuimedo): when you request a driver in a docker operation, such -# as docker network create, docker searches /usr/lib/docker or /etc/docker -# subdirs for network/storage plugin specs or json definitions. so it's either -# have ansible place the file there, or volume mount it and let the container -# place the file there -- name: Starting kuryr container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ kuryr_image_full }}" - name: "kuryr" - privileged: True - volumes: - - "{{ node_config_directory }}/kuryr/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "/run:/run:shared" - - "/usr/lib/docker:/usr/lib/docker" - when: inventory_hostname in groups['compute'] diff --git a/ansible/roles/kuryr/tasks/upgrade.yml b/ansible/roles/kuryr/tasks/upgrade.yml index 1f16915ad9..9eca42dec5 100644 --- a/ansible/roles/kuryr/tasks/upgrade.yml +++ b/ansible/roles/kuryr/tasks/upgrade.yml @@ -1,4 +1,7 @@ --- - include: config.yml -- include: start.yml +- include: bootstrap.yml + +- name: Flush handlers + meta: flush_handlers