- name: "Set 'postgresql_install: True' and 'postgresql_enabled: True'"
  set_fact:
    postgresql_install: True
    postgresql_enabled: True    # Revert just below if...

- name: "Set 'postgresql_enabled: False' if not moodle_enabled"
  set_fact:
    postgresql_enabled: False
  when: not moodle_enabled    # and not (pathagar_enabled is defined and pathagar_enabled)

- name: POSTGRESQL - run 'postgresql' role (Enable&Start or Disable&Stop PostgreSQL)
  include_role:
    name: postgresql


- name: Enable http://box/moodle via NGINX, by installing {{ nginx_conf_dir }}/moodle-nginx.conf from template
  template:
    src: moodle-nginx.conf.j2
    dest: "{{ nginx_conf_dir }}/moodle-nginx.conf"    # /etc/nginx/conf.d
  when: moodle_enabled

- name: Disable http://box/moodle via NGINX, by removing {{ nginx_conf_dir }}/moodle-nginx.conf
  file:
    path: "{{ nginx_conf_dir }}/moodle-nginx.conf"    # /etc/nginx/conf.d
    state: absent
  when: not moodle_enabled

- name: Restart 'nginx' systemd service
  systemd:
    name: nginx
    state: restarted
