---
# 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 is 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: Start the search daemon
  service: name=sphinxsearch state=started enabled=yes
- name: Enable search
  command: sed -i 's/\(Configure::write(.Search.enabled.,\).*)/\1 true)/' {{code_dir}}/app/Config/core.php

---
# 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 is 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: Start the search daemon
  service: name=sphinxsearch state=started enabled=yes
- name: Enable search
  replace:
    path: '{{code_dir}}/app/Config/core.php'
    regexp: 'Configure::write\(.Search\.enabled.,[^)]+\)'
    replace: 'Configure::write(''Search.enabled'', true)'
    validate: 'php -l %s'

Use replace module instead of custom sed command
Use replace module instead of custom sed command

Cleaner code + php syntax check
