stack_host.ymlΒΆ

---
- name: "πŸ›‘ stop discourse container gracefully if it exist"
  ansible.builtin.command: "container stop {{ DISCOURSE_CONTAINER }}"
  register: container_stop
  changed_when: container_stop.rc == 0
  failed_when: >
    container_stop.rc != 0 and
    'No such container' not in (container_stop.stderr | default(''))

- name: "πŸ—‘οΈ remove discourse container if it exist"
  ansible.builtin.command: "container rm {{ DISCOURSE_CONTAINER }}"
  register: container_action
  changed_when: container_action.rc == 0
  failed_when: >
    container_action.rc != 0 and
    'No such container' not in (container_action.stderr | default(''))

- name: "πŸ”— add central database temporary to discourse network"
  command: "container network connect {{ DISCOURSE_NETWORK }} {{ DISCOURSE_DATABASE_CONTAINER }}"
  failed_when: >
    result.rc != 0 and
    not (result.stderr | default('') | docker_network_noop('connect'))
  register: result
  when:
    - DISCOURSE_DATABASE_IS_SHARED | bool
    - IS_COMPOSE_MODE

- name: "πŸ”¨ {{ DISCOURSE_LAUNCHER_ACTION }} discourse"
  shell: >
    ./launcher {{ DISCOURSE_LAUNCHER_ACTION }} {{ DISCOURSE_CONTAINER }}
    {% if DOCKER_IN_CONTAINER | bool %}--skip-prereqs{% endif %}
  args:
    executable: /bin/bash
    chdir: "{{ DISCOURSE_REPOSITORY_DIR }}"
  register: discourse_rebuild
  retries: 3
  delay: 60
  until: discourse_rebuild.rc == 0
  no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"

- name: "πŸ”— Connect '{{ DISCOURSE_CONTAINER }}' to its shared swarm overlays"
  command: "container network connect {{ discourse_overlay }} {{ DISCOURSE_CONTAINER }}"
  loop: "{{ ([DISCOURSE_WEB_NETWORK] + ([DISCOURSE_PG_NETWORK] if (DISCOURSE_DATABASE_IS_SHARED | bool) else []) + ([DISCOURSE_REDIS_NETWORK] if (DISCOURSE_REDIS_SHARED
    | bool) else []) + ([DISCOURSE_LITELLM_NETWORK] if (DISCOURSE_LITELLM_ENABLED | bool) else [])) }}"
  loop_control:
    loop_var: discourse_overlay
    label: "{{ discourse_overlay }}"
  register: discourse_overlay_connect
  changed_when: discourse_overlay_connect.rc == 0
  failed_when: >
    discourse_overlay_connect.rc != 0 and
    not (discourse_overlay_connect.stderr | default('') | docker_network_noop('connect'))
  when: IS_SWARM_MODE | bool