---
- name: "stop and remove discourse container if it exist"
  community.docker.docker_container:
    name: "{{ DISCOURSE_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 discourse network"
  command: "docker network connect {{ DISCOURSE_NETWORK }} {{ database_host }}"
  failed_when: >
    result.rc != 0 and
    'already exists in network' not in result.stderr
  register: result
  when: applications | get_app_conf(application_id, 'features.central_database', False)
  listen: recreate discourse

- name: rebuild discourse
  shell: ./launcher rebuild {{ DISCOURSE_CONTAINER }}
  args:
    executable: /bin/bash  
    chdir: "{{ DISCOURSE_REPOSITORY_DIR }}"
  listen: recreate discourse
  no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"