---

- name: Create databases
  mysql_db:
    name: "{{ item.mysql.database | default(item.project) }}"
    state: present
  with_items: items.results | map(attribute='ansible_facts') | byattr("state", "present") | notbyattr("mysql", false) | list
  when: item.mysql != false
  register: database_created

- name: Import dumps
  mysql_db:
    name: "{{ item.item.mysql.database | default(item.item.project) }}"
    state: import
    target: "{{ item.item.mysql.import }}"
  with_items: database_created.results | byattr("changed", true)
  when: database_created.changed and item.item.mysql.import is defined

- name: Remove and clean databases
  mysql_db:
    name: "{{ item.mysql.database | default(item.project) }}"
    state: absent
  with_items: items.results | map(attribute='ansible_facts') | byattr("state", "absent") | list

---

- name: Create databases
  mysql_db:
    name: "{{ item.mysql.database | default(item.project) }}"
    state: present
  with_items: items.results | map(attribute='ansible_facts') | byattr("state", "present") | notbyattr("mysql", false) | list
  when: item.mysql != false
  register: database_created

- name: Import dumps
  mysql_db:
    name: "{{ item.item.mysql.database | default(item.item.project) }}"
    state: import
    target: "{{ item.item.mysql.import | regex_replace('\\[\\[path\\]\\]', item.item.path) | regex_replace('\\[\\[project\\]\\]', item.item.project) }}"
  with_items: database_created.results | byattr("changed", true)
  when: database_created.changed and item.item.mysql.import is defined

- name: Remove and clean databases
  mysql_db:
    name: "{{ item.mysql.database | default(item.project) }}"
    state: absent
  with_items: items.results | map(attribute='ansible_facts') | byattr("state", "absent") | list

Allow vars in MySQL dump path
Allow vars in MySQL dump path
