---

- set_fact:
    _project_databases: '{{ (_project_databases | default([])) + item.databases | list }}'
  when: item.remove is not defined or item.remove != true
  with_items: '{{ devbox_projects }}'

- set_fact:
    _project_remove_databases: '{{ (_project_remove_databases | default([])) + item.databases | list }}'
  when: item.remove is defined and item.remove == true
  with_items: '{{ devbox_projects }}'

- name: Create or update databases
  mysql_db:
    name: "{{ item }}"
    state: present
  when: _project_databases|length
  with_items: '{{ _project_databases }}'

- name: Remove databases
  mysql_db:
    name: "{{ item }}"
    state: absent
  when: _project_remove_databases|length
  with_items: '{{ _project_remove_databases }}'

---

- set_fact:
    _project_databases: '{{ (_project_databases | default([])) + item.databases | list }}'
  when: (item.remove is not defined or item.remove != true) and item.databases is defined
  with_items: '{{ devbox_projects }}'

- set_fact:
    _project_remove_databases: '{{ (_project_remove_databases | default([])) + item.databases | list }}'
  when: (item.remove is defined and item.remove == true) and item.databases is defined
  with_items: '{{ devbox_projects }}'

- name: Create or update databases
  mysql_db:
    name: "{{ item }}"
    state: present
  when: _project_databases|length
  with_items: '{{ _project_databases }}'

- name: Remove databases
  mysql_db:
    name: "{{ item }}"
    state: absent
  when: _project_remove_databases|length
  with_items: '{{ _project_remove_databases }}'

Allow not to define a database in projects config
Allow not to define a database in projects config
