---
- name: check/run upgrade
  command: sudo -u www-data php updater.phar --no-interaction
  args:
    chdir: "{{ nc_dir }}/updater"
    warn: false
  register: upgrade_result
  changed_when: upgrade_result.stdout is not search('Nothing to do.')
  notify: update and fix data base

- name: update apps
  command: "sudo -u www-data php ./occ app:update --all"
  args:
    chdir: "{{ nc_dir }}"
    warn: false
  register: cmd_result
  changed_when: cmd_result.stdout | length > 0

- name: install extra apps
  command: "sudo -u www-data php ./occ app:install {{ item }}"
  args:
    chdir: "{{ nc_dir }}"
    warn: false
  with_items: "{{ nc_apps }}"
  register: cmd_result
  changed_when: cmd_result.stdout is not search('already installed')
  failed_when: cmd_result.stdout is not search('already installed') and cmd_result.rc != 0
