---
# Playbook to setup sphinx server, index sentences and start the search daemon

- name: Check whether code directory is present or not
  shell: ' [ -d  {{code_dir}} ] '
  register: code_status
  ignore_errors: yes
- name: Database import/update fail message
  fail: msg="The code directory is not present in {{code_dir}}. Please run update_code.yml first to create these directories. Also, you need to have the tatoeba database setup. Use setup_database.yml for that."
  when: code_status|failed

- name: Create directories for sphinx
  file: path={{item}} state=directory recurse=yes mode=744 owner=sphinxsearch group=sphinxsearch
  with_items:
  - "{{sphinx_index_dir}}"
  - "{{sphinx_log_dir}}"
  - "{{sphinx_binlog_path}}"
- name: Generate sphinx.conf
  shell: ./app/Console/cake sphinx_conf > /etc/sphinxsearch/sphinx.conf chdir={{code_dir}}
- name: Create indexes
  command: indexer --all
  when: sphinx_create_indexes == true
- name: Set sphinxsearch to start with system startup
  command: sed -i 's/START=no/START=yes/' /etc/default/sphinxsearch
- name: Start the search daemon
  service: name=sphinxsearch state=started enabled=yes

---
# Playbook to setup sphinx server, index sentences and start the search daemon

- name: Check whether code directory is present or not
  shell: ' [ -d  {{code_dir}} ] '
  register: code_status
  ignore_errors: yes
- name: Database import/update fail message
  fail: msg="The code directory is not present in {{code_dir}}. Please run update_code.yml first to create these directories. Also, you need to have the tatoeba database setup. Use setup_database.yml for that."
  when: code_status|failed

- name: Create directories for sphinx
  file: path={{item}} state=directory recurse=yes mode=744 owner=sphinxsearch group=sphinxsearch
  with_items:
  - "{{sphinx_index_dir}}"
  - "{{sphinx_log_dir}}"
  - "{{sphinx_binlog_path}}"
- name: Generate sphinx.conf
  shell: ./app/Console/cake sphinx_conf > /etc/sphinxsearch/sphinx.conf chdir={{code_dir}}
- name: Create indexes
  become: true
  become_user: sphinxsearch
  command: indexer --all
  when: sphinx_create_indexes == true
- name: Set sphinxsearch to start with system startup
  command: sed -i 's/START=no/START=yes/' /etc/default/sphinxsearch
- name: Start the search daemon
  service: name=sphinxsearch state=started enabled=yes

Make sure Sphinx indexes are created by sphinx user
Make sure Sphinx indexes are created by sphinx user
