---
- name: "stop and remove discourse container if it exist"
  docker_container:
    name: "{{applications[application_id].container}}"
    state: absent
  register: container_action
  failed_when: container_action.failed and 'No such container' not in container_action.msg
  listen: recreate discourse
  
- name: "add central database temporary to {{application_id}}_default"
  command: docker network connect {{applications[application_id].network}} central-{{ database_type }}
  failed_when: >
    result.rc != 0 and
    'already exists in network' not in result.stderr
  register: result
  when: applications | is_feature_enabled('central_database', application_id)
  listen: recreate discourse

- name: rebuild discourse
  shell: > 
    ./launcher rebuild {{applications[application_id].container}}
    2>&1 | tee >(systemd-cat -t rebuild-{{ application_id }})
  args:
    executable: /bin/bash  
    chdir: "{{docker_repository_directory }}"
  listen: recreate discourse