diff --git a/ansible/roles/influxdb/defaults/main.yml b/ansible/roles/influxdb/defaults/main.yml index 4633af3e2b..81e4efffaa 100644 --- a/ansible/roles/influxdb/defaults/main.yml +++ b/ansible/roles/influxdb/defaults/main.yml @@ -1,6 +1,19 @@ --- project_name: "influxdb" +influxdb_services: + influxdb: + container_name: influxdb + group: influxdb + enabled: true + image: "{{ influxdb_image_full }}" + volumes: + - "{{ node_config_directory }}/influxdb/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "influxdb:/var/lib/influxdb" + - "kolla_logs:/var/log/kolla/" + + #################### # Docker #################### diff --git a/ansible/roles/influxdb/handlers/main.yml b/ansible/roles/influxdb/handlers/main.yml new file mode 100644 index 0000000000..2e52dc9636 --- /dev/null +++ b/ansible/roles/influxdb/handlers/main.yml @@ -0,0 +1,20 @@ +--- +- name: Restart influxdb container + vars: + service_name: "influxdb" + service: "{{ influxdb_services[service_name] }}" + config_json: "{{ influxdb_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + influxdb_container: "{{ check_influxdb_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 influxdb_confs.changed | bool + or influxdb_container.changed | bool diff --git a/ansible/roles/influxdb/tasks/config.yml b/ansible/roles/influxdb/tasks/config.yml index f9b7544f89..b1aae85017 100644 --- a/ansible/roles/influxdb/tasks/config.yml +++ b/ansible/roles/influxdb/tasks/config.yml @@ -4,20 +4,50 @@ path: "{{ node_config_directory }}/influxdb" state: "directory" recurse: yes - when: inventory_hostname in groups['influxdb'] + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ influxdb_services }}" - name: Copying over config.json files template: - src: "{{ item }}.json.j2" + src: "{{ item.key }}.json.j2" dest: "{{ node_config_directory }}/influxdb/config.json" - when: inventory_hostname in groups['influxdb'] - with_items: - - influxdb + register: influxdb_config_jsons + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ influxdb_services }}" + notify: + - Restart influxdb container - name: Copying over influxdb config file + vars: + service: "{{ influxdb_services['influxdb']}}" template: src: "{{ role_path }}/templates/{{ item }}.conf.j2" dest: "{{ node_config_directory }}/influxdb/influxdb.conf" - when: inventory_hostname in groups['influxdb'] + register: influxdb_confs + when: + - inventory_hostname in groups[service.group] + - service.enabled | bool with_items: - - influxdb + - "influxdb" + notify: + - Restart influxdb container + +- name: Check influxdb 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_influxdb_containers + when: + - action != "config" + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ influxdb_services }}" + notify: + - Restart influxdb container diff --git a/ansible/roles/influxdb/tasks/deploy.yml b/ansible/roles/influxdb/tasks/deploy.yml index 1f16915ad9..dd26ecc34d 100644 --- a/ansible/roles/influxdb/tasks/deploy.yml +++ b/ansible/roles/influxdb/tasks/deploy.yml @@ -1,4 +1,5 @@ --- - include: config.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers diff --git a/ansible/roles/influxdb/tasks/reconfigure.yml b/ansible/roles/influxdb/tasks/reconfigure.yml index 6049df4746..e078ef1318 100644 --- a/ansible/roles/influxdb/tasks/reconfigure.yml +++ b/ansible/roles/influxdb/tasks/reconfigure.yml @@ -1,47 +1,2 @@ --- -- name: Ensuring the containers up - kolla_docker: - name: "influxdb" - action: "get_container_state" - register: container_state - failed_when: container_state.Running == false - when: inventory_hostname in groups['influxdb'] - -- include: config.yml - -- name: Check the configs - command: docker exec influxdb /usr/local/bin/kolla_set_configs --check - changed_when: false - failed_when: false - register: check_results - when: inventory_hostname in groups['influxdb'] - -# 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: "influxdb" - action: "get_container_env" - register: container_envs - when: inventory_hostname in groups['influxdb'] - -- name: Remove the containers - kolla_docker: - name: "influxdb" - action: "remove_container" - register: remove_containers - when: - - config_strategy == "COPY_ONCE" - - inventory_hostname in groups['influxdb'] - -- include: start.yml - when: remove_containers.changed - -- name: Restart containers - kolla_docker: - name: "influxdb" - action: "restart_container" - when: - - config_strategy == 'COPY_ALWAYS' - - inventory_hostname in groups['influxdb'] +- include: deploy.yml diff --git a/ansible/roles/influxdb/tasks/start.yml b/ansible/roles/influxdb/tasks/start.yml deleted file mode 100644 index 1a98e71234..0000000000 --- a/ansible/roles/influxdb/tasks/start.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- name: Starting influxdb container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ influxdb_image_full }}" - name: "influxdb" - volumes: - - "{{ node_config_directory }}/influxdb/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "influxdb:/var/lib/influxdb" - - "kolla_logs:/var/log/kolla/" - when: inventory_hostname in groups['influxdb'] diff --git a/ansible/roles/influxdb/tasks/upgrade.yml b/ansible/roles/influxdb/tasks/upgrade.yml index 1f16915ad9..dd26ecc34d 100644 --- a/ansible/roles/influxdb/tasks/upgrade.yml +++ b/ansible/roles/influxdb/tasks/upgrade.yml @@ -1,4 +1,5 @@ --- - include: config.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers