---
- name: "copy xml configs"
  copy:
    src: mbstat.xml
    dest: "{{ mbstat.files.config }}"
    mode: "0755"
    owner: root
    group: root

- name: "replace mbstat timezone"
  replace:
    path: "{{ mbstat.files.config }}"
    regexp: "{timezone}"
    replace: "{{ timezone.stdout }}"

- name: "replace main log"
  replace:
    path: "{{ mbstat.files.config }}"
    regexp: "{error_log_path}"
    replace: "{{ mbstat.files.log_main }}"

- name: "replace debug log"
  replace:
    path: "{{ mbstat.files.config }}"
    regexp: "{debug_log_path}"
    replace: "{{ mbstat.files.log_debug }}"

- name: "replace mysql password"
  replace:
    path: "{{ mbstat.files.config }}"
    regexp: "{password}"
    replace: "{{ mbstat.software.database.mysql_pass }}"
  when: mbstat.software.database.mysql_pass != ""
  no_log: true

- name: "replace mysql username"
  replace:
    path: "{{ mbstat.files.config }}"
    regexp: "{username}"
    replace: "{{ mbstat.software.database.mysql_user }}"

- name: "replace mysql database name"
  replace:
    path: "{{ mbstat.files.config }}"
    regexp: "{database}"
    replace: "{{ mbstat.software.database.mysql_db }}"

- name: "replace mysql host"
  replace:
    path: "{{ mbstat.files.config }}"
    regexp: "{server_host}"
    replace: "{{ mbstat.software.database.mysql_host }}"

- name: "create hard links"
  file:
    src: "{{ mbstat.files.config }}"
    dest: "{{ mbstat.dirs.chroot }}{{ mbstat.files.config }}"
    state: hard
    force: yes
    mode: "0755"
    owner: root
    group: root
