---
# tasks file for tikv

- name: create deploy directories
  file: path={{ item }} state=directory mode=0755
  with_items:
  - "{{ tikv_log_dir }}"
  - "{{ tikv_data_dir }}"
  - "{{ tikv_status_dir }}"

- name: "load customized config: tikv.yml"
  include_vars: file={{ playbook_dir }}/conf/tikv.yml name=tikv_conf_custom

- name: load default config
  include_vars: file=default.yml name=tikv_conf_default

- name: generate dynamic config
  set_fact:
    tikv_conf_generated:
      metric:
        address: >-
          {{ hostvars[groups.monitoring_servers[0]].ansible_host | default(hostvars[groups.monitoring_servers[0]].inventory_hostname) ~ ':' ~
           (hostvars.get(groups.monitoring_servers.0).pushgateway_port | default('9091')) |
           default('') }}
      server:
        labels: "{{ labels }}"
      rocksdb:
        wal-dir: "{{ wal_dir }}"
      raftstore:
        raftdb-path: "{{ raftdb_path }}"

- name: generate final config
  set_fact:
    tikv_conf: "{{ tikv_conf_custom | with_default_dicts(tikv_conf_generated, tikv_conf_default) }}"

- debug: var=tikv_conf

- name: create config file
  template: src=tikv.toml.j2 dest=/etc/tikv.toml mode=0644

- include_tasks: "binary_deployment.yml"

- name: prepare firewalld white list
  set_fact:
    firewalld_ports: "{{ [tikv_port ~ '/tcp'] + firewalld_ports }}"
