---
#Application tasks to be customized and to run after the main provision
- name: Install global npm packages
  become: yes
  become_user: vagrant
  shell: export NVM_DIR="$HOME/.nvm" &&. "$NVM_DIR/nvm.sh" && npm install -g bower recess

- name: Install Composer dependencies
  shell: make install_composer
  become: yes
  become_user: vagrant
  ignore_errors: yes
  args:
    chdir: /vagrant/

- name: Install assets dependencies
  shell: export NVM_DIR="$HOME/.nvm" &&. "$NVM_DIR/nvm.sh" && make install_asset_dependencies
  become: yes
  become_user: vagrant
  ignore_errors: yes
  args:
    chdir: /vagrant/

- name: Install assets
  shell: export NVM_DIR="$HOME/.nvm" &&. "$NVM_DIR/nvm.sh" && make install_assets
  become: yes
  become_user: vagrant
  ignore_errors: yes
  args:
    chdir: /vagrant/

- name: Run application setup
  become: yes
  become_user: vagrant
  shell: 'php bin/setup system:install --email=admin@{{ hostname }}.vb --password=admin --db-host=127.0.0.1 --db-port=3306 --db-user={{ mariadb.user }} --db-password={{ mariadb.password }} --db-template=en-simple --appbox={{ mariadb.appbox_db }} --databox={{ mariadb.databox_db }} --server-name=www.{{ hostname }}.vb --data-path=/vagrant/datas -y'
  args:
    chdir: /vagrant/

- name: Create extra databox
  become: yes
  become_user: vagrant
  shell: 'php bin/console databox:create {{ mariadb.alt_databox_db }} admin@{{ hostname }}.vb'
  args:
    chdir: /vagrant/

- name: Enable debugger for host IP addresses
  shell: php bin/setup system:config add debugger.allowed-ips "{{ item }}"
  with_items: '{{ host_addresses }}'
  args:
    chdir: /vagrant/

- name: Disable API SSL requirement
  shell: php bin/setup system:config set registry.api-clients.api-require-ssl false
  args:
    chdir: /vagrant/

- name: Enable API routes
  shell: php bin/setup system:config set registry.api-clients.api-enable true
  args:
    chdir: /vagrant/

- name: Create ElasticSearch indexes
  shell: php bin/console searchengine:index -c
  args:
    chdir: /vagrant/

- name: Make exiftool executable
  file:
    path: /vagrant/vendor/exiftool/exiftool/exiftool
    mode: 0755
